In a right triangle, the square of the length of one side is equal to the sum of
ID: 3607524 • Letter: I
Question
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. Stephanie has the integer lengths of three sides of a triangle and needs to know if it is a right triangle or not. Also include a code for when an invalid input was put in. All lengths must be positive integers.Write a program to solve this problem.
NOTE: The user must be allowed to input the values of the sides in ANY ORDER!
Write the program to implement your algorithm. Test your program using your test cases.
Explanation / Answer
This is your program in C language -
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,c;
printf("Enter the sides of a triangle :- ");
scanf("%d%d%d",&a,&b,&c);
if((a>b && a>c) && a<(b+c) || (b>a && b>c) && b<(a+c) || (c>a && c>b) && c<(a+b) || (a==b && b==c))
{
if(a==b && b==c)
printf("This triangle is an equilateral triangle. ");
if(a==b || b==c || a==c)
printf("This triangle is an isosceles triangle. ");
if(a!=b && b!=c && a!=c)
printf("This triangle is a scalene triangle. ");
if(a>b && a>c)
{
if(a*a==(b*b)+(c*c))
printf("This triangle is a right angled triangle. ");
}
else if(b>a && b>c)
{
if(b*b==(a*a)+(c*c))
printf("This triangle is a right angled triangle. ");
}
else
{
if(c*c==(a*a)+(b*b))
printf("This triangle is a right angled triangle. ");
}
}
else
printf("These are the sides of a invalid triangle. ");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.