Step 1: Begin
Step 2: Read a, b, c
Step 3: s = (a + b + c)/2
Step 3: area = √ (s (s-a) (s-b) (s-c))
Step 4: Print area
Step 5: End
Flowchart
Program
/*calculate the area of a triangle using three sides */
#include
#include
#include
void main()
{
float area, a, b, c ,s;
clrscr();
printf ("enter three sides of a triangle ");
scanf ("%f%f%f",&a,&b,&c);
s = (a + b + c)/2;
area=sqrt( s * (s-a) * (s-b) * (s-c));
printf ("Area of a triangle is %f", area);
}
Illustration of the program:
Variables area is used for area of a triangle, s as parameter and a, b, c are used for three sides of triangle .
If you entered , 1.5 2 2.5 as a, b, c, s = (1.5 + 2 + 2.5)/2=3.0000,
then area = √( 3 * (3 - 1.5) * (3 - 2) * (3 - 2.5))
= √ 2.25
= 1.5
So, the output is
Area of a triangle is 1.5
No comments:
Post a Comment