Pages

Friday, July 05, 2013

Write a program to find Area of a Triangle in C++

Area of a Triangle Formula: A = (1/2) * b * h

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
    #include <iostream.h>
    #include <conio.h>
    int main()
    { 
     float b, h, c, A;   
     cout << " Area of a Triangle Formula: A = (1/2) * b * h\n";   
     cout << " Enter the value of b <base>?\n";
     cin  >> b;
     cout << " Enter the value of h <height>?\n";
     cin  >> h;
       b  = b * h;
       A  = b * 0.5;
     cout << " Area of a Triangle = " << A << " m^2 "<< endl;     
     getch();
     return 0;
            } // end main

Output:

 Area of a Triangle Formula: A = (1/2) * b * h
 Enter the value of b <base>?
4
 Enter the value of h <height>?
7
 Area of a Triangle = 14 m^2

No comments:

Post a Comment