C Function that prints perimeter and area of right triangle.

//C Function that prints perimeter and area of right triangle.


#include<stdio.h>
#include<math.h>
float triangle_perimeter(float a,float b,float c);
float triangle_area(float a,float b,float c);
int main()
{
	float a, b, c, peri,ar,s;
	printf("\nPlease Enter three sides of triangle\n");
	scanf("%f%f%f",&a,&b,&c);
	peri=triangle_perimeter(a,b,c);
	ar=triangle_area(a,b,c);
	printf("\nPerimeter of Traiangle = %.2f\n", peri);
	printf("\nArea of triangle = %.2f\n",ar);
	return 0;
}
float triangle_area(float a,float b,float c)
{
	float s,area;
	s = (a+b+c)/2;
	area = sqrt(s*(s-a)*(s-b)*(s-c));
	return area;
}


float triangle_perimeter(float a,float b,float c)
{
	float area,perimeter;
	perimeter = a+b+c;
	return perimeter;
}

Output :
Please Enter three sides of triangle
2
3
4

Perimeter of Traiangle = 9.00

Area of triangle = 2.90



Leave a comment