Question

In: Computer Science

Write in c++ as simple as possible In a right triangle, the square of the length...

Write in c++ as simple as possible

In a right triangle, the square of the length on one side is equal to the sum of the squares of the lengths of the other two sides.  Write a program that prompts the user to enter the length of three sides of the tringle (as doubles) and the outputs a message indication whether the triangle is a right triangle.  You should split this into two functions (but only one .cpp file).  One function is main() where you input the values of the three sides, and then print out the final answer. The other function is where you determine if the triangle is a right triangle. Watch out about using == with doubles. Put comments at the top of your code.

Solutions

Expert Solution

/*Write a program to check whether triangle is right angled triangle or not. */
#include<iostream.h>
#include<conio.h>
int findRightTriangle(double,double,double);
void main()
{
double a,b,c;
int ch=0;
clrscr();
cout<<"Enter first side of triangle: ";
cin>>a; //accepts one side of triangle from user
cout<<"Enter second side of triangle: ";
cin>>b;
cout<<"Enter third side of triangle: ";
cin>>c;
ch=findRightTriangle(a,b,c); //calls findRightTriangle function
if(ch==1)
cout<<"Triangle is right triangle"<<endl;
else
cout<<"Triangle is not right triangle"<<endl;
getch();
}
int findRightTriangle(double a,double b,double c)
{
if((a*a+b*b==c*c)||(a*a+c*c==b*b)||(c*c+b*b==a*a)) //pythagoras theorem
return 1;
else
return 0;
}

Output:

Please give positive rating.


Related Solutions

Q-2) In a right triangle, the square of the length of one side is equal to...
Q-2) In a right triangle, the square of the length of one side is equal to the sum of squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle or not.
Write class Hypotenuse that calculates the length of the hypotenuse of a right triangle and return...
Write class Hypotenuse that calculates the length of the hypotenuse of a right triangle and return to HypotenuseTest class. The lengths of the other two sides are given by the user by using HypotenuseTest class and send into Hypotenuse class. Hypotenuse class should take two arguments of type double and return the hypotenuse as a double into HypotenuseTest’s Main method. Finally, the HypotenuseTest class displays the hypotenuse side of a triangle.
Find the lengths of the arms of a right triangle whose hypotenuse has length c if...
Find the lengths of the arms of a right triangle whose hypotenuse has length c if these arms have a ratio of (a) 3;4 and c=15, (b) 5;12 and c=26, (c) 8;15 and c =170 and (d) 1;2 and c=10
5.11 LAB: Drawing a right triangle c++ This program will output a right triangle based on...
5.11 LAB: Drawing a right triangle c++ This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as...
Given a right triangle with one leg length of a, one leg length of x-3 and...
Given a right triangle with one leg length of a, one leg length of x-3 and the hypo is x, how does a affect x? Shown on a graph. I solved for a, it is equal to the square root of 6x-9.... I am having a difficult time interpreting how a affects x.. I am not sure how to graph
Write a C# console program that fills the right to left diagonal of a square matrix...
Write a C# console program that fills the right to left diagonal of a square matrix with zeros, the lower-right triangle with -1s, and the upper left triangle with +1s. Let the user enter the size of the matrix up to size 21. Use a constant and error check. Output the formatted square matrix with appropriate values. Refer to the sample output below. Sample Run: *** Start of Matrix *** Enter the size of square (<= 21): 5 1 1...
Triangle Class write a class for triangle input is the length of the 3 edges you...
Triangle Class write a class for triangle input is the length of the 3 edges you can use arccos: math.acos(you_input_here), the output is -pi to pi (in real value) class math class Triangle(): # initialize here def __init__(xxx): # you need to modify this line          # your function angles is to output the 3 angles (in degree) in ascending order def angles():          # is_equilateral outputs True if the triangle is equilateral def is_equilateral():   ...
Find a b c of a right triangle. with a perimeter of 18.
Find a b c of a right triangle. with a perimeter of 18.
a) The triangle △ ABC is right-angled with right angle at corner C and angle α...
a) The triangle △ ABC is right-angled with right angle at corner C and angle α at corner A. Calculate a = | BC |, given that c = | AB | = 8, and that tan α = 12. Calculate a= ? b) In the triangle △ ABC before the designations a = | BC |, b = | CA |, c = | AB |, and ∠A = α, ∠B = β and ∠C = γ. Find c,...
write a java program for area and perimeter of right triangle
write a java program for area and perimeter of right triangle
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT