Today, we will learn how to calculate surface area of a triangle. We will use the formula for surface area:
area = 1 /2 x base x height
Therefore, we must have base and height of the given triangle. We will prompt the user to input base and height of given triangle. Then we will use the above mentioned formula to calculate area of the given triangle easily.
Basic Statements Used in this Program
The basic statements used to write this C language program are as follows:
- Pre processor directives to include header files stdio.h for input / output operations.
- Writing main() function
- variable declaration statements
- printf() function for displaying messages
- scanf() function for input
- Use assignment statement for calculating simple formula to calculate area of triangle
Source Code for C Program how to calculate surface area of a triangle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/* C Program how to calculate surface area of a triangle */ #include<stdio.h> int main() { float area, base, height; printf("Enter base of triangle ="); scanf("%f", &base); printf("Enter height of triangle ="); scanf("%f", &height); area = 1.0 / 2.0 * base * height; printf("Area of Triangle =%f", area); return 0; } |