➤ Program to calculate area of triangle without using Heron's formula .
#include<stdio.h> int main() { float a,b,area; printf("Enter base and height of triangle: "); scanf("%f%f",&a,&b); area=(a*b)/2; printf("Area=%.2f",area); return 0; }
OUTPUT :Enter base and height of triangle
Enter base and height of triangle: 4 2 Area=4.00
➤ Program to calculate the area of triangle using Heron's formula .
#include<stdio.h>
#include<math.h>
int main()
{ float a,b,c,s,area;
printf("Enter three sides of triangle: ");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt((s*(s-a)*(s-b)*(s-c)));
printf("Area is = %.2f",area);
return 0;
}
OUTPUT :
Enter three sides of triangle:3 5 7
Area is = 6.50