Problem:
Given the lengths of three sides of a triangle. Write a program in C which decides the type (Right Angled, Acute, Obtuse, Isosceles, Scalene, Equilateral etc.) of the triangle.
Source Code:
/*to decide the type of triangle*/#include <stdio.h>
#include <stdlib.h>
int main()
{
float a,b,c;
printf("Enter the length of three sides of a triangle: ");
scanf("%f%f%f",&a,&b,&c);
if(a > b + c || b > c + a || c > a+b)
{
printf("This is not a triangle.");
system ("pause");
exit(0);
}
else if( a == b && b == c && c == a)
printf("This is an equilateral triangle.");
else if(a==b || b==c || c==a)
printf("This is an isosceles triangle.");
else if(a*a == b*b + c*c || b*b == c*c + a*a || c*c == a*a + b*b)
printf("This is a right angled triangle.");
else if(a*a > b*b + c*c || b*b > c*c + a*a || c*c > a*a + b*b)
printf("This is an obtuse angled triangle.");
else if(a*a < b*b + c*c || b*b < c*c + a*a || c*c < a*a + b*b)
printf("This is an acute angled triangle.");
else
printf("This is a scalene triangle.");
system ("pause");
return 0;
}
Sample Output:
Enter the length of three sides of a triangle: 5 6 7
This is an acute angled triangle.
No comments:
Post a Comment