Friday 26 July 2013

Chapter 2 solutions Problem [F][g]

Question-If the three sides of a triangle are entered through the
keyboard, write a program to check whether the triangle is
isosceles, equilateral, scalene or right angled triangle.
Solution-
it's a good question to practice conditional operators . here is it's solution.

#include<stdio.h>
#include<math.h>

int main()
{
float a,b,c;
printf("Enter the length of the sides\n");
scanf("%f%f%f",&a,&b,&c);
if(a==b&&b==c)
printf("Equilateral Triangle\n");
 if(a==b&&b!=c||b==c&&c!=a||c==a&&a!=b)
printf("Isosceles Triangle\n");
 if(a!=b&&b!=c&&c!=a)
printf("Scalene Triangle\n");
if( pow(a,2)+pow(b,2)==pow(c,2)|| pow(c,2)+pow(b,2)==pow(a,2)|| pow(c,2)+pow(a,2)==pow(b,2))
printf("Right angle triangle\n");
return 0;
}



No comments:

Post a Comment