Write a c program to find whether a triangle can be formed or not. If not display this triangle is not possible. if the triangle can be formed then check the triangle formed is equilateral, isosceles, scalene or a right-angled triangle.
Answers
Example
Input
Input first side: 7
Input second side: 10
Input third side: 5
Output
Triangle is valid
Answer:
C program is written below :
Step-by-step explanation:
We know ,
A triangle is a valid triangle ,
If side1 + side2 > side3 and side1 + side3 > side2 and side2 + side3 > side1
Also,
A triangle is said to be an Equilateral Triangle, if all its sides are equal.
If a, b, c are three sides of triangle.
Then, the triangle is equilateral only if a == b == c.
Similarly,
A triangle is said to be an Isosceles Triangle, if its two sides are equal.
If a, b, c are three sides of triangle.
Then, the triangle is isosceles if either a == b or a == c or b == c.
Also,
A triangle is said to be a Scalene Triangle, if none of its sides are equal.
And
A triangle is said to be Right-angled Triangle, if sum of squares of any two sides is equal to square of third sides [ Pythagorus theorem ]
C- program
# include<stdio.h>
int main()
{
float a,b,c;
printf("\n Enter value of Side 1 of the traiangle : ");
scanf("%f",&a);
printf("\n Enter value for Side 2 of the traiangle : ");
scanf("%f",&b);
printf("\n Enter value for Side 3 of the traiangle : ");
scanf("%f",&c);
if ( a < ( b + c ) && b < ( a + c ) && c < ( a + b ) )
{
printf("\n The Triangle can be formed " ) ;
if ( a == b && a == c && b == c )
printf("\n It is an Equilateral Triangle " ) ;
else if ( a == b | | a == c | | b == c )
printf("\n It is a Isosceles Triangle " ) ;
else if( ( a * a ) == ( b * b ) + ( c * c ) | | ( b * b ) == ( a * a ) + ( c * c ) | |
( c * c ) == ( a * a ) + ( b * b ) )
printf("\n It is a Right-angle Triangle");
else if( a != b && a != c && b != c )
printf("\n It is a Scalene Triangle.");
}
else
printf("\n The Triangle cannot be formed " ) ;
getch ( ) ;
return 0 ;
}