Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Triangle - C++ Note: Cannot use arrays, or classes..only functions. Write a prog

ID: 671939 • Letter: T

Question

Triangle - C++
Note: Cannot use arrays, or classes..only functions.

Write a program to read in three integers representing line lengths. Determine if the three line segments form a right triangle. If it is not a right triangle, is it a valid triangle? Allow the three numbers to be input in any order. An input number will be 1 <= n <= 5000.

right triangle: c^2 = a^2 + b^2
triangle: sum of two sides is larger than the third.

Restrictions: Use a function to read in three values,one to test for right triangle and one to test for triangle.
Output: Print results out showing the relation holds.

Explanation / Answer

Program:

#include <iostream>
#include <Math.h>
using namespace std;

void isValidTriangle(int a, int b, int c)
{
   if(((a+b)>c)||((c+b)>a)||((c+a)>b))
       cout<<endl<<"But this is a Valid triangle";  
   else
       cout<<endl<<"Also this is not a right triangle";
}

void isRightTriangle(int a, int b, int c)
{
   if(pow(c,2)==(pow(a,2)+pow(b,2)))
       cout<<endl<<"This is a right triangle";
   else
   {
       cout<<endl<<"This is not a right triangle";  
       isValidTriangle(a,b,c);
   }
}

int main()
{
   int a,b,c;
   cout<<"Enter three sides of a triangle(1-5000)";
   cin>>a>>b>>c;
   isRightTriangle(a,b,c);
   return 0;
}

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

Output1:

Enter three sides of a triangle(1-5000)
8 6 10

This is a right triangle
-------------------------------- .

Output2:

Enter three sides of a triangle(1-5000)
67 90 23

This is not a right triangle
But this is a Valid triangle
--------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote