Write a C program to input side of a triangle and check whether triangle is valid or not using if else. How to check whether a triangle can be formed or not if sides of triangle is given using if else in C programming. Logic to check triangle validity if sides are given in C program.

0

  1. /**
  2.  * C program to check whether a triangle is valid or not using logical AND operator
  3.  */

  4. #include <stdio.h>

  5. int main()
  6. {
  7.     int side1, side2, side3;

  8.     /* Input all three sides of a triangle */
  9.     printf("Enter three sides of triangle: \n");
  10.     scanf("%d%d%d", &side1, &side2, &side3);

  11.     if((side1 + side2 > side3) && (side1 + side3 > side2) && (side2 + side3 > side1))
  12.     {
  13.         printf("Triangle is valid.");
  14.     }
  15.     else
  16.     {
  17.         printf("Triangle is not valid.");
  18.     }

  19.     return 0;
  20. }

⥷🍭

Post a Comment

0Comments
Post a Comment (0)