An Algorithm to check whether the triangle is valid or not if 3 sides of a triangle are entered.

Note : The triangle is valid if the sum of two sides is greater than the largest of the 3 sides.

  1. START
  2. Input 3 sides of triangle s1,s2 and s3.
  3. Check if (s1>s2 && s1>s3 && (s2+s3)>s1) then GOTO step 8 else continue.
  4. Check if (s2>s1 && s2>s3 && (s1+s3>s2) then GOTO step 8 else continue.
  5. Check if (s3>s1 && s3>s2 && (s1+s2)>s3) then GOTO step 8 else continue.
  6. Print Triangle is Invalid
  7. GOTO step 9
  8. Print Triangle is Valid
  9. END / STOP

Flowchart to check whether the triangle is valid or not if 3 sides of a triangle are entered.

Flowchart to check whether the triangle is valid or not if 3 sides of a triangle are entered.
Flowchart to check whether the triangle is valid or not if 3 sides of a triangle are entered.

If the three sides of a triangle are entered through the keyboard, C-Code to check whether the triangle is valid or not. The triangle is valid if the sum of two sides is greater than the largest of the three sides.

#include<stdio.h>
void main()
{
int s1,s2,s3;
printf("Enter three sides of the triangle s1,s2,s3 :");
scanf("%d%d%d",&s1,&s2,&s3);
if(s1>s2 && s1>s3 && (s2+s3)>s1)
   {
   printf("The triangle is valid");
   }
if(s2>s1 && s2>s3 && (s1+s3>s2))
      {
      printf("The triangle is valid");
      }
if (s3>s1 && s3>s2 && (s1+s2)>s3)
     {
     printf("the triangle is valid");
     }
else
 {
 printf("the triangle is not valid");
 }
}