Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    C Program to Find Area of a Triangle

    C Programming Examples


    This C example program performs simple mathematical calculations to find the area of a triangle. It asks the user to provide the triangle's vertices A, B, and C and calculates to find its area.

    A triangle is a two-dimensional three-sided polygon closed figure in geometry with three edges and three vertices.

    Example:

    C program to find the area of a triangle:

    #include <stdio.h>
    #include <math.h> /* It is ecessary for using sqrt function  */
    
    void main()
    {
        /*Variable Declaration*/
        float a, b, c, s, area;
    
        /*Taking user input*/
        printf("Enter the three sides, a, b, and c, of the triangle:");
        scanf("%f%f%f", &a, &b, &c);
    
        /*Calculate the area of the triangle*/
        s = (a + b + c) / 2;
        area = sqrt((s *(s - a) *(s - b) *(s - c)));
        printf("\n The area of the triangle is %f.", area);
    }

    Program Output:

    Enter the three sides, a, b, and c, of the triangle:
    15
    10
    15
    The area of the triangle is 70.710678.

    The area of a triangle can be calculated with the help of various formulas. Here we have used Heron's formula, which is shown in the figure below:



    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.