# write a program to enter two sides a and b of a right triangle from keyboard calculate its area and perimeter

Question
3 views

write a program to enter two sides a and b of a right triangle from keyboard calculate its area and perimeter

check_circle

Step 1

Given below is the C++ program to enter the two sides of a right triangle and then calculate its area and perimeter.

Step 2

#include <iostream>

#include <cmath>

using namespace std;

double Perimeter(double a, double b); //function declaration

double Area(double a, double b); //function declaration

int main()

{

double a,b;

cout<<"Enter a b:";

cin>>a>>b; // Enter values of a and b

cout<<"Perimeter:"<<Perimeter(a,b)<<endl; //function calling

cout<<"Area:"<<Area(a,b)<<endl;  //function calling

}

double Perimeter(double a, double b) //function definition

{

double c,per;

c=sqrt(pow(a,2)+pow(b,2));  //finding value of c

per=a+b+c;  //calculating perimeter

return per;

}

double Area(double a, double b) //function definition

{

double area=0.5*a*b; //calculating area

return area;

}

Step 3

In the above program, both area and perimeter are calculated by entering values of a and b. To enter the values of a and b, cin function is used. To calculate perimeter of right triangle,...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

### Computer Science 