Problem in triangle verification in C

0

The program aims to identify whether a triangle is equilateral, isosceles or scalene. But there is an error in the isosceles identification line, where if the user places values of equal entries on the first two sides and different in the last, it is not recognized.

Example:

  • measure of side1: 3 ;
  • measure of side2: 4 ;
  • measure of side3: 2 ;

Code:

#include<stdio.h>
int main(){

    int L1,L2,L3;
    int equilatero,isoceles,escaleno;


    printf("media do lado1:");
    scanf("%d",&L1);

    printf("media do lado2:");
    scanf("%d",&L2);

    printf("media do lado3:");
    scanf("%d",&L3);

    equilatero = (L1 == L2)&&(L1 == L3);
    printf("seu triangulo eh equilatero: %d\n",equilatero);

    isoceles = ((L1==L2)||(L1==L3)||(L2==L3))&&((L1!=L2)||(L2=!L3)||(L1=!L3));
    printf("seu triangulo eh isoceles: %d \n",isoceles);

    escaleno = (L1 != L2)&&(L2 != L3)&&(L1 != L3);
    printf("seu triangulo eh escaleno: %d \n",escaleno);

    return 0;
}
    
asked by anonymous 21.02.2017 / 17:35

1 answer

0

Your isosceles check is wrong, so it's not right, the correct one would be:

isoceles = (((L1 == L2) && (L2 != L3)) || ((L2 == L3) && (L3 != L1)) || ((L3 == L1) && (L3 != L2)));

I hope I have helped.

    
21.02.2017 / 18:36