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.
5 Steps to Find the Area of Triangle in C
- The first step is to initialize 3 variables. a, b, and area.
- The Second step is to take input from the user and store the Height and Base in Variables a and b.
- The third step is to apply the Area of Triangle = 1/2 * Base * Height. formula.
- In the fourth step, store the value of Area of Triangle = 1/2 * Base * Height in the third variable area.
- The last step is to print the value of the area.
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
You can also find the Area of Triangle in C++ and Java Programming Languages. Below the solution in the C++ and Java.
#include
ReplyDelete#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);
}