Thursday 28 January 2016

Solution of URI 1045 :: Triangle Types


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    double ara[3];
    int a,b,c=1;
    double d,e,f,g,h,A,B,C,i,j,k,l,m,n,o,p;
    scanf("%lf%lf%lf", &ara[0], &ara[1], &ara[2]);
    for(a=0; a<3; a++)
    {
        for(b=c; b<3; b++)
        {
            if(ara[a]<ara[b])
            {
                e=ara[b];
                ara[b]=ara[a];
                ara[a]=e;
            }
        }
        c++;
    }
    A=ara[0]; B= ara[1]; C=ara[2];
    d=B+C;
    i=B*B+C*C;
    j=A*A;

    if(A>=d)
        printf("NAO FORMA TRIANGULO\n");
    else if(i==j)
        printf("TRIANGULO RETANGULO\n");
    else if(i<j)
        printf("TRIANGULO OBTUSANGULO\n");
    else if(i>j)
        printf("TRIANGULO ACUTANGULO\n");
    if(A==B && B==C)
        printf("TRIANGULO EQUILATERO\n");
    else if(A==B || B==C || A==C)
        printf("TRIANGULO ISOSCELES\n");
    return 0;
}

2 comments:

  1. did you run this code?..It doesn't work properly when all the sides are equal.

    ReplyDelete

Note: only a member of this blog may post a comment.