Header Ads Widget

Responsive Advertisement

Area Of Triangle C Code

 

AREA OF TRIANGLE C CODE


Here's an example of a C program that calculates the area of a triangle given the lengths of its three sides (a, b, and c) using Heron's formula:




#include <stdio.h>

#include <math.h>


int main() {

    double a, b, c, s, area;

    printf("Enter the lengths of the three sides of the triangle: ");

    scanf("%lf%lf%lf", &a, &b, &c);

    s = (a + b + c) / 2;

    area = sqrt(s * (s-a) * (s-b) * (s-c));

    printf("The area of the triangle is: %lf", area);

    return 0;

}


Note that this code uses the sqrt() function from the math.h library to calculate the square root. And also you need to include the math library if you want to use sqrt function.


The output of this program will be a single floating-point value, which is the area of the triangle calculated using Heron's formula.


Example:


Enter the lengths of the three sides of the triangle: 3 4 5

The area of the triangle is: 6.00000


It will ask the user to input the values of the three sides of the triangle and then it will calculate the area of the triangle using Heron's formula, and then it will print the area of the triangle.



Post a Comment

0 Comments