Write a c program to find the area of a triangle

C program for area of a triangle

Formula of area of any triangle:

Area = √(s*(s-a)*(s-b)*(s-c))
Where s = (a + b + c)/2

C code:


int main(){
    float a,b,c;
    float s,area;
    printf("Enter size of each sides of triangle");
    s = (a+b+c)/2;
    area = sqrt(s*(s-a)*(s-b)*(s-c));
    printf("Area of triangle is: %.3f",area);
    return 0;

Sample output:

Enter size of each sides of the triangle: 2 4 5
Area of triangle is: 3.800


rajagopal said...

this answer is wonderful really i like you

mrb said...

when i put 2 4 6 shows wrong answer
i.e., when s= even

Manabendu Bardhan said...

thats not a valid tringle.....for a valid tringle {if(a+b>c && b+c>a && c+a>b)}

Manabendu Bardhan said...

I missed a thing i.e your a(2)+b(4)is not greater then c(6)

razu said...


Mahesh Chandra Dhakal said...

Who made this program in this website thank you very much. May god give you power and arrange to you all the situation to help the other like this.

Anonymous said...

Thanx for the help

Anonymous said...

Thanks for the help...but what if write float a,b,c,s,area; instead of
float a,b,c;
float s,area;

Ritesh gupta said...

Write a C program to print the following triangle:

Anonymous said...

thnks man this makes programing c easy

dileep kumar said...

why you write in last printf 3f

Leyla Kalhor said...

please help me. i want to write a program in C. that gets 3 sides and gives 3 angles. pleaseeeeee

Leyla Kalhor said...

this is my mail.. please heeeeeelp me. leylakalhor@rocketmail.com

Unknown said...
This comment has been removed by the author.
Jwel Rana said...

Why you write %.3f

Aditya Limbu said...

three digits after decimal point.
Example : 3.800

If it was %.5f
It would have been - 3.80000

Aditya Limbu said...
This comment has been removed by the author.