You're online now.

Hurray! you are online now.

Area of Triangle C

// Write a c program to calcuate the area of triangle.
    #include <stdio.h>
    int main() {
        int Height, Base;
        float areaOfTriangle;
        printf("Enter the Height and Base of Triangle : ");
        scanf("%d %d", &Height, &Base);
        areaOfTriangle = 0.5 * Height * Base;
        printf("Area of Triangle : %f", areaOfTriangle);
    	return 0;
  1. The program starts with by including the standard input/output stdio.h header file.
  2. The main() function defined.
  3. Three variables are declared: Height and Base are both integer data type, areaOfTriangle is the float data type.
  4. A prompt message display on the user screen using the printf() function, for asking the user enter the Height and Base of the triangle.
  5. The scanf() function is used to read/takes the value from the user, for Height and Base variable and given value stored in Height and Base variable respectively.
  6. The area of triangle is calculated using the formula (0.5* Height * Base) and store the calculated value in the areaOfTriangle variable.
  7. Finally, the result(Area of Triangle) is displayed on the user screen using the printf() function with the help of format specifier %f to print the float value of the calculated area of triangle.
  8. The return statement is used to exit the program successfully.
🖤 0
Buy me coffee ☕



No comments here...