WAP to calculate the area of a triangle using function

Write a program to calculate the area of a triangle using function

#include<stdio.h>
#include<math.h>

float triangle(float,float,float);

int main() {
	float a,b,c;
	printf("Enter the sides of triangle: \n");
	scanf("%f%f%f",&a,&b,&c);
	
	if(a<b+c && b<c+a && c<a+b) 
	  printf("Area of triangle is %f",triangle(a,b,c));
	else
	  printf("This sides does not form triangle.");
	return 0;
}

float triangle(float x, float y, float z) {
	float s,A;
	s=(x+y+z)/2;
	A=sqrt(s*(s-x)*(s-y)*(s-z));
	return A;
}

Output

Enter the sides of triangle:
3
4
5
Area of triangle is 6.000000

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments