Q: if the length of a triangle are input through the keyboard, write a program to find the area of triangle.
#include <stdio.h>
#include <math.h>
int main()
{
float area,a,b,c,s; // a,b,c are sides of triangle //
printf("enter side of triangle : ");
scanf("%f%f%f",&a,&b,&c);
if (a+b<=c ||b+c<=a ||c+a<=b ||a<0 ||b<0 ||c<0) //to check whether the triangle is possible or not//
printf("triangle is not possible");
else //if the triangle is possible//
{
s=(a+b+c)/2; /* to find the semi perimeter of triangle denoted as s/2 */
area=sqrt(s*(s-a)*(s-b)*(s-c)); /*formula used to find area of triangle*/
printf("area of triangle is %f",area);
}
return 0;
}
-----------------------------------------
output :
enter side of triangle : 3
4
5
area of triangle is 6.000000
-----------------------------------------
output :
enter side of triangle : 66
7
44
triangle is not possible
#include <math.h>
int main()
{
float area,a,b,c,s; // a,b,c are sides of triangle //
printf("enter side of triangle : ");
scanf("%f%f%f",&a,&b,&c);
if (a+b<=c ||b+c<=a ||c+a<=b ||a<0 ||b<0 ||c<0) //to check whether the triangle is possible or not//
printf("triangle is not possible");
else //if the triangle is possible//
{
s=(a+b+c)/2; /* to find the semi perimeter of triangle denoted as s/2 */
area=sqrt(s*(s-a)*(s-b)*(s-c)); /*formula used to find area of triangle*/
printf("area of triangle is %f",area);
}
return 0;
}
-----------------------------------------
output :
enter side of triangle : 3
4
5
area of triangle is 6.000000
-----------------------------------------
output :
enter side of triangle : 66
7
44
triangle is not possible
Comments
Post a Comment