PLAY WITH CODING

Home Basic Program If & Else Loops Conversion Pattern logo

Program Based on If & Else

Program to input angles of the triangle and check whether a triangle is valid or not

Input - Output

Input
Enter the angle of the triangle: 70 65 45

Output
Triangle is valid

Input
Enter the angle of the triangle: 70 0 110

Output
Triangle is invalid

Algorithm

Step 1: START

Step 2: Enter the angle of the triangle.

Step 3: Check the condition:

    if sum of all angle of the triangle=180 and each angle must be>0

      print triangle is valid

   else

      print triangle is not valid

Step 4: END

CODE


/* Check triangle is valid or not */
#include  <stdio.h>
int main()
{
      int angle1,angle2,angle3,sum;
      printf(" Enter angles of the triangle : ");
      scanf("%d%d%d",&angle1,&angle2,&angle3);
      sum=angle1+angle2+angle3;
      if(sum==180 && angle1>0 && angle2>0 && angle3>0)
            printf(" Triangle is valid ");
       else
           printf(" Triangle is not valid ");
    return 0;
}


/* Check Triangle is valid or not */
#include <iostream>
using namespace std;
int main()
{
      int angle1,angle2,angle3,sum;
      cout<<" Enter angles of the triangle : ";
      cin>>angle1>>angle2>>angle3;
      sum==angle1+angle2+angle3;
      if(sum=180 && angle1>0 && angle2>0 && angle3>0)
            cout<<" Triangle is valid ";
       else
           cout<<" Triangle is not valid ";
    return 0;
}

OutPut

Enter the angle of the triangle: 70 65 45

Triangle is valid