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

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

#include <iostream>
#include <cmath>
using namespace std;
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;
	cout << "\nPlease Enter three sides of triangle\n";
	cin >> a;
	cin >> b;
	cin >> c;
	peri=triangle_perimeter(a,b,c);
	ar=triangle_area(a,b,c);
	cout << "\nPerimeter of Traiangle = "<< peri <<"\n";
	cout << "\nArea of triangle = "<< ar <<"\n";
        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