Algorithm
Step 1: Begin
Step 2: Read b, h
Step 3: area = b * h / 2
Step 4: Print area
Step 5: End
Flowchart
Program
/*calculate the area of a triangle using base and height */
#include
#include
void main()
{
float area, b, h;
clrscr();
printf ("enter base and height of a triangle ");
scanf ("%f%f",&b,&h);
area=b * h / 2;
printf ("Area of a triangle is %f", area);
}
Illustration of the program:
Variables area is used for area of a triangle and b, h used for base and height of a triangle respectively.
If you entered 6 as base and 7.5 as height, area of a triangle is 6 * 7.5 / 2 = 22.5
So, the output is
Area of a triangle is 22.5
No comments:
Post a Comment