write c program to Find the Area of a Triangle

Ram Pothuraju

 #include <stdio.h>


int main()

{

    float base, height, area;

    

    printf("Enter the base of the triangle: ");

    scanf("%f", &base);

    

    printf("Enter the height of the triangle: ");

    scanf("%f", &height);

    

    // Calculate the area of the triangle

    area = 0.5 * base * height;

    

    printf("The area of the triangle is: %.2f\n", area);

    

    return 0;

}


In this program, we first declare three variables - base, height, and area - all of which are floating-point numbers.

Then, we prompt the user to enter the base and height of the triangle using the printf and scanf functions.

Next, we calculate the area of the triangle using the formula 0.5 * base * height, where 0.5 represents one-half of the base multiplied by the height. We store the result in the area variable.

Finally, we print the result using the printf function, using the %0.2f format specifier to round the value to two decimal places.

When the program is run, it will output the area of the triangle based on the user's input.

Post a Comment

0Comments

Post a Comment (0)