I need to work out an algorithm that receives 3 real values and checks whether these values can be the lengths of the sides of a triangle, and in this case, return the type of triangle formed.
So that x
, y
and z
form a triangle and it is necessary that the following property be satisfied: the length of each side of a triangle and less than the sum of the length of the other two sides
Any value that I put in my algorithm it responds as scalene which is the first if
, what's wrong with it?
#include <stdio.h>
int func(float x, float y, float z)
{
float a,b,c;
float tri;
a=x+y;
b=x+z;
c=y+z;
if(a>z || b>y || c>x)
{
if(x==y && x==z && y==z)
{
tri=1;
}
else
{
if((x==y && y==z) || (x==z && y==z) || (x==y && x==z))
{
tri=2;
}
if (x!=y && x!=z && y!=z )
{
tri=3;
}
}
}
return tri;
}
int main()
{
float x,y,z;
float tri;
printf("Informe 3 valores reais: \n");
scanf("%f %f %f",&x,&y,&z);
tri=func(x,y,z);
if (tri==1)
{
printf("O triangulo eh escaleno.\n");
}
if(tri==2)
{
printf("O triangulo eh isoceles\n");
}
if(tri==3)
{
printf("O triangulo eh escaleno\n");
}
return 0;
}