This is another small program we can create beside calculate rectangle area.
It is calculate an area of a triangle.
Just like calculate rectangle area program, first we have to know the formula we can use to calculate the area of triangle.
Or we can change the formula in the calculate rectangle area program.
The formula is:
Area = 0.5 * bottom * height
The complete syntax is like the example below:
#include "iostream.h"
#include "conio.h"
main()
{
int area, bt, hg;
cout<< "Calculate Triangle Area";
cout<< "\n\nInsert long of the bottom: ";
cin>> bt;
cout<< "Insert the height: ";
cin>> hg;
area = 0.5*bt*hg;
cout<< "The Area of the Triangle is: "<< area;
getch();
}
The result is shown by the pictures below:
0 comments:
Post a Comment