how we can write an algorithm to find an area of a triangle
Answers
Write Down Algorithm of C++ Program Area of Triangle
1. Start
2. Input a,b,c
3. Calculate s = (a + b + c ) / 2
4. Calculate area = sqrt( s*(s-a)*(s-b)*(s-c))
5. print "Area of Triangle=", area
6. End
Develop Flowchart of C++ Program Area of Triangle
Generally we prepare a flowchart and algorithm which is independent of any programming language so here is a better flowchart version for C++ Program Area of Triangle with mathematical formula instead of C++ arithmetic expressions.
Flowchart for C++ Program How To Calculate Area of triangle when 3 side are input
Write Down Source Code of C++ Program Area of Triangle
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main( )
{
float a,b,c,s,area;
clrscr();
cout<<"Enter side A of triangle = ";
cin>>a;
cout<<"Enter side B of triangle = ";
cin>>b;
cout<<"Enter side C of triangle = ";
cin>>c;
s = (a + b + c ) / 2;
area = sqrt ( s * (s - a ) * (s - b ) * (s - c ) ) ;
cout<< "Area of Triangle = "<<area;
getch();
}
The algorithm for calculating the area of a triangle is,
- START
- Read base and height.
- Input the values from the user.
- Store 1/2 * base * height in the variable 'area'.
- Print the area.
- End
In the above algorithm,
- The variables 'base' and 'height' are created to take the inputs.
- After that, the area is stored in a new variable 'area'.
- Finally the desired output for the area of the triangle is printed.