In this C program we will see how to find the Area of triangle using formula:
Area = √ s (s-a) (s-b) (s-c) , here s = semi-perimeter = a+b+c /2 and a, b, c are sides of triangle.
- LOGIC:
First we'll calculate semi-perimeter and then we'll find area using the formula. Since formula of area have square root, so we'll include <math.h> file in our program.
- ALGORITHM:
- Start
- Input three sides of triangle: a, b, c.
- Calculate semi-perimeter, s = a+b+c /2
- Calculate area of triangle, area = √s (s-a) (s-b) (s-c)
- Print the area of triangle
- End
- CODE:
#include <stdio.h>
#include <math.h>
int main ()
{
/*declare variables for 3 sides,
semi-perimeter and area.*/
float a,b,c,s,area;
printf("Enter sides of triangle : ");
//input values of 3 sides from user.
scanf("%f %f %f",&a,&b,&c);
//calculate semi-perimeter
s=(a+b+c)/2;
//calculate area
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of the triangle is : %.2f",area);
return 0;
}
- OUTPUT:
Enter sides of triangle : 3 4 5
Area of the triangle is : 6.00
- CHALLENGE.1:
Try to make a program to find sum of roots and product of roots of a quadratic equation.
Solution to above Challenge.1
That's it for today. If you have any problem then don't hesitate to ask.
Share, Subscribe and keep coding...
Comments
Post a Comment