In: Computer Science
TEXT ONLY PLEASE ( PLEASE NO PDF OR WRITING)
C++ CODE
Instructions
In a right triangle, the square of the length of 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 lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle.
If the triangle is a right triangle, output It is a right angled triangle
If the triangle is not a right triangle, output It is not a right angled triangle
Note: The OR (||) operator will return true when either of the three condition is true.
Code to copy:
#include <iostream>
using namespace std;
int main()
{
// Declare the necessary int variables
int side1, side2, side3;
// Prompt user to enter the length of the sides
cout<<"Enter the lengths of the three sides of the triangle: "<<endl;
// Read the user inputs
cin>>side1>>side2>>side3;
// Check if the square of one side is equal to the sum of squares of the other two sides
if(((side1*side1) == ((side2*side2)+(side3*side3))) || ((side2*side2) == ((side1*side1)+(side3*side3))) || ((side3*side3) == ((side1*side1)+(side2*side2))))
{
// Print the triangle is right-angled
cout<<"It is a right angled triangle"<<endl;
}
else
{
// Print the triangle is not right-angled
cout<<"It is not a right angled triangle"<<endl;
}
}
Screenshot of code:
Sample output:
1
2