C program! Write a program triangles.c that reads in the lengths of the three si
ID: 3744373 • Letter: C
Question
C program!
Write a program triangles.c that reads in the lengths of the three sides of a triangle. First, verify that the lengths do form a triangle: adding any two sides should yield a number that exceeds the third. Next, if it is a triangle, determine if the triangle is equilateral: all sides would have equal length; determine if the triangle is isosceles: two sides have equal length, which is different from the third. Finally, determine if the triangle is right-angled: the sum of the square of two sides would yield the square of the third.
Example input/output:
Enter the lengths of three sides of the triangle: 3.3 19.6 3.3
Output: The three sides do not form a triangle.
Enter the lengths of three sides of the triangle: 3.3 3.3 3.3
Output: The three sides form a triangle. The triangle is equilateral.
Enter the lengths of three sides of the triangle: 3 4 5
Output: The three sides form a triangle. The triangle is right-angled.
Enter the lengths of three sides of the triangle: 6.3 6.3 5
Output: The three sides form a triangle. The triangle is isosceles.
Explanation / Answer
please give thumbs up, thanks
CODE:
#include<stdio.h>
#include<math.h>
int main()
{
double a,b,c;
printf("Enter the length of three Sides of the triangle : ");
scanf("%lf %lf %lf",&a,&b,&c);
bool istriangle=false;
if(a+b>c && b+c>a && c+a>b)
istriangle=true;
if(istriangle==false)
{
printf("The three Sides do not form a triangle");
return 0;
}
if((a*a)+(b*b)==(c*c) || (c*c)+(b*b)==(a*a) || (a*a)+(c*c)==(b*b))
{
printf("The three sides form a triangle. The triangle is right-angled.");
}
else if(a==b && b==c)
{
printf("The three sides form a triangle. The triangle is equilateral.");
}
else if((a==b & a!=c) || (b==c & b!=a) || (a==c & a!=b))
{
printf("The three sides form a triangle. The triangle is isosceles.");
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.