Question

In: Computer Science

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.

Solutions

Expert Solution

Since you have not mentioned the programming language, I have answered in C++. In case, you need any other programming language, then let me know in the comment section.


Please look at my code and in case of indentation issues check the screenshots.

-------------main.cpp---------------

#include <iostream>
using namespace std;

int main()
{
   float side1, side2, side3;
   cout << "Enter the length of side1: ";       //read 3 sides
   cin >> side1;
   cout << "Enter the length of side2: ";
   cin >> side2;
   cout << "Enter the length of side3: ";
   cin >> side3;

   if(side1*side1 == side2*side2 + side3*side3)       //check if sum squares of side2, side3 is equal to side1 square
       cout << "The triangle is a right angled triangle" << endl;
  
   else if(side2*side2 == side1*side1 + side3*side3)   //check if sum squares of side1, side3 is equal to side2 square
       cout << "The triangle is a right angled triangle" << endl;

   else if(side3*side3 == side1*side1 + side2*side2)   //check if sum squares of side1, side2 is equal to side3 square
       cout << "The triangle is a right angled triangle" << endl;

   else
       cout << "The triangle is a NOT a right angled triangle" << endl;

   return 0;  
}

--------------Screenshots--------------

--------------------Output-----------------------

----------------------------------------------------------------------------------------

Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs down.
Please Do comment if you need any clarification.
I will surely help you.

Thankyou


Related Solutions

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()...
Write a program that prompts the user for the length of one side of a triangle...
Write a program that prompts the user for the length of one side of a triangle and the sizes of the two adjacent angles in degrees and then displays the length of the two other sides and the size of the third angle.
Three charges of +Q are at the three corners of a square of side length L....
Three charges of +Q are at the three corners of a square of side length L. The last corner is occupied by a charge of -Q. Find the electric field at the center of the square.
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
A square loop of wired with side length 2 cm is in the plane of the...
A square loop of wired with side length 2 cm is in the plane of the page. At time t= 0, a 9 T magnetic field is directed into the page. The field changes to 4 T directed into the page in 0.25 seconds. What is the magnetic flux through the loop of wire at time, t = 0? What is the magnetic flux through the loop of wire 0.25 seconds later?What is the emf induced in the loop of...
Right Triangle:If the square of one side equals the sum of the squares of the other...
Right Triangle:If the square of one side equals the sum of the squares of the other two sides. in python
A triangle has side lengths of 3cm, 4cm, and, 6cm. Is it a right triangle explain?
A triangle has side lengths of 3cm, 4cm, and, 6cm. Is it a right triangle explain?
Each small square in the grid for this graph has one side equal to 1 pound of bolts and one side equal to 1 dollar per pound.
Jack Hardware sold 6 pounds of bolts yesterday at a price of $3,.00 per pound. This point is represented by the black plus symbol on the diagram below, which plots the price of bolts (measured in dollars, per pound) and the quantity sold (measured in pounds).Each small square in the grid for this graph has one side equal to 1 pound of bolts and one side equal to 1 dollar per pound. The area of one small square is therefore...
triangle ABC is a right-angled triangle with the size of angle ACB equal to 74 degrees.
 triangle ABC is a right-angled triangle with the size of angle ACB equal to 74 degrees. The lengths of the sides AM, MQ and QP are all equal. Find the measure of angle QPB.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT