26/01/2023

C Program to Find Area of Triangle Given Base And Height

Write a C Program to Find Area of Triangle Given Base And Height. As we all know the Area of Triangle is 1/2 * Base * Height. So according to the formula, we need the Base and Height of the triangle. In this problem, we have to store the value of Base in the first variable and the value of Height in the second variable and in the last simply we have to apply the formula. 

Below I have taken all major 5 steps to find the Area of Triangle. You can also find the Complete Code with the Output of the given problem statement C Program to Find Area of Triangle Given Base And Height.

C Program to Find Area of Triangle Given Base And Height

5 Steps to Find the Area of Triangle in C


  1. The first step is to initialize 3 variables. a, b, and area.
  2. The Second step is to take input from the user and store the Height and Base in Variables a and b.
  3. The third step is to apply the Area of Triangle = 1/2 * Base * Height. formula.
  4. In the fourth step, store the value of Area of Triangle = 1/2 * Base * Height in the third variable area.
  5. The last step is to print the value of the area.

Area of Triangle = 1/2 * Base * Height

Area of Triangle = 1/2 * Base * Height

C Program to Find Area of Triangle


#include<stdio.h>

int main()
{
    /*Program By Ghanendra Yadav
    Visit http://www.programmingwithbasics.com/
    */
    float b,h,area;

    printf("Enter Height and Base Of Triangle : ");
    scanf("%f %f",&h,&b);

    area = (h*b)/2;
    printf("Area of Triangle is: %f\n",area);
    return 0;
}

Output Area of Triangle in C


Code Output Area of Triangle in C Language

You can also find the Area of Triangle in C++ and Java Programming Languages. Below the solution in the C++ and Java.

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

1 comment:

  1. #include
    #include
    int main()
    {
    float area,x,s,a,b,c;
    printf("Enter three sides of the triangle");
    scanf("%f%f%f",&a,&b,&c);
    s=((a+b+c)/2);
    x=s*(s-a)*(s-b)*(s-c);
    area=pow(x,0.5);
    printf("Area is %f",area);
    }

    ReplyDelete