# Algorithm and problem solving with C

Requirement
You are to get 3 sides of a triangle and validate if the triangle is valid, if it is valid your program needs to find out if the triangle is equilateral, isoceles or scalene.

Algorithm

```prompt "Enter 3 integers";
get side1, side2, side3;

//triangle validation function
if !(side1 + side2 > side3):
set test_result = 1

else
if !(side2 + side3 > side1):
set test_result=1

else
if!(side1 + side3 > side2):
else set test_result = 0;
endif
endif
endif
endif

if (test_result=0)
display "Invalid triangle"
//equilateral (all sides equal)
else
if (side1 == side2 && side2 == side3):
display "Equilateral triangle";

else
//isosceles (at least 2 sides are equal)
if (side1 == side2 || side1 == side3 || side2 == side3):
display "Isosceles triangle";

//scalene (anything else)
else
display "Scalene triangle"

endif
endif
endif
endif
```

The program in c. You can use the onlinegdb.com to validate the result

```#include
#include

bool Triangle_Validation(float,float,float);

bool Triangle_Validation(float side1,float side2, float side3){
bool triangle;
if (!(side1+side2 > side3)){
triangle = 0;
}
else if (!(side2+side3 > side1)){
triangle = 0;
}
else if (!(side1+side3 > side2)){
triangle = 0;
}
else {
triangle = 1;
}
return triangle;
}

int main()
{
float side1,side2,side3;
bool test_result;
printf("Enter the values of 3 sides of a triangle:");
scanf("%f%f%f",&side1,&side2,&side3);

test_result = Triangle_Validation(side1,side2,side3);
if (test_result == 0){
printf("Invalid triangle");
}
else if (side1==side2 && side2==side3 && side1==side3){
printf("Equilateral Triangle"); //all sides equal
}
else if (side1==side2 || side2==side3 || side1==side3){
printf("Isoceles Triangle"); //at least two sides equal
}
else {
printf("Scalene Triangle"); //use 5 4 3 to test, pythogarean type of triangle
}

return 0;
}
```