a)
Write a C Program to calculate the area of triangle using the formula
area = ( s (s-a) (s-b)(s-c))1/2 where s= (a+b+c)/2
Program:
[bkrishna@localhost cp1]$ vi areatri.c
#include<stdio.h>
#include<math.h>
main()
{
float a,b,c,s,area;
printf("Enter sides of triangle (a,b,c values) :");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of the traingle (whose sides are %f %f %f) is: %f\n",a,b,c,area);
}
Output:
[bkrishna@localhost cp1]$ cc areatri.c -lm
[bkrishna@localhost cp1]$ ./a.out
Enter sides of triangle (a,b,c values) :3 4 5
Area of the traingle (whose sides are 3.000000 4.000000 5.000000) is: 6.000000

0 comments: