Friday, 19 August 2016

Problem Statement 2:
Given three sides of triangle a,b and c, determine if the given triangle is equilateral, scalene or
isoceles triangle.
Constraints :
1<t<100
a, b and c are floating point numbers
0.0<a<1000.0
0.0<b<1000.0
0.0<c<1000.0
Input :
First line specifies the number of test cases t.
Each of the next t lines contains three real numbers denoting a, b and c respectively.
Assume that for all possible triplets of a,b and c, the triangle is always possible.
Output:
Each line contains either of these three strings : “Equilateral Triangle”, “Scalene Triangle”, or
“Isoceles Triangle” depending on type of traingle. Remember OJ is case sensitive.
Sample Input :
4
2 3 3
5 7 7
1 3.0 2.5
2.0 4.5 3.8
4 4 4.0
Sample Output :
Isoceles Triangle
Isoceles Triangle

 Solution:

#include<stdio.h>
int main()
{
    int i,test;
    float a,b,c;
    scanf("%d",&test);
    for(i=1;i<=test;i++)
    {
        scanf("%f %f %f",&a,&b,&c);
        if ((a+b<=c) || (a+c<=b) || (b+c)<=a)
            printf("no triangle")
        else if(a==b && b==c)
            printf("equileteral triangle\n");
        if(a*a+b*b==c*c)
            printf("right angled triangle")
        else if( ((a==b) || (b==c)) || (a==c))
            printf("isoceles triangle\n");
        else
            printf("scalene triangle\n");
    }
}

No comments:

Post a Comment