Write me a function that receives three integer inputs for the lengths of the sides of a triangle and returns one of four values to determine the triangle type (1=scalene, 2=isosceles, 3=equilateral, 4=error). Generate test cases for the function assuming another developer coded the function
Click for Solution
  • A #include<stdio.h>

    void triangle(int a, int b, int c){
    if(a<0 || b<0 || c<0)
    printf("Error!");
    else if(a+b<=c || a+c<=b || b+c<=a)
    printf("Not a triangle");
    else if(a==b && b==c && a==c)
    printf("Equilateral triangle");
    else if(a==b || b==c || a==c)
    printf("Isosceles triangle");
    else if(a!=b && b!=c && c!=a && a+b>c && a+c>b && b+c>a)
    printf("Scalene triangle");

    }

    int main(){
    int a, b, c, n;
    printf("Enter number of elements: ");
    scanf("%d", &n);
    if(n!=3)
    printf("Error!");
    else{
    printf("Enter a, b, c: ");
    scanf("%d%d%d", &a, &b, &c);
    triangle(a, b, c);
    }
    return 0;
    }

[Insert Code]