Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
Article

write c program to Find the Area of a Triangle

Reviewed & accurate
AI Summary

 #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.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments