C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Decision Making Programs in C

Check whether triangle is valid (angles sum = 180)

Introduction

A triangle is valid if the sum of its three interior angles equals 180°.
This is a fundamental property of triangles in geometry.

For example:

  • If angles are 60°, 60°, 60° → Valid triangle
  • If angles are 50°, 60°, 70° → Valid triangle
  • If angles are 90°, 80°, 30° → Invalid triangle (because sum ≠ 180)

In this program:

  • We will take three angle inputs from the user.
  • Calculate their sum.
  • Check whether the sum is equal to 180° to determine validity.

 

C Program: Check whether triangle is valid (angles sum = 180)

C

#include <stdio.h>

 

int main() {

    float angle1, angle2, angle3, sum;

 

    // Input angles of triangle

    printf("Enter first angle: ");

    scanf("%f", &angle1);

    printf("Enter second angle: ");

    scanf("%f", &angle2);

    printf("Enter third angle: ");

    scanf("%f", &angle3);

 

    // Calculate sum of angles

    sum = angle1 + angle2 + angle3;

 

    // Check validity

    if (sum == 180 && angle1 > 0 && angle2 > 0 && angle3 > 0) {

        printf("The triangle is valid.\n");

    } else {

        printf("The triangle is not valid.\n");

    }

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter first angle: 60
Enter second angle: 60
Enter third angle: 60
The triangle is valid.

OUTPUT 2 :
Enter first angle: 90
Enter second angle: 80
Enter third angle: 30
The triangle is not valid.

OUTPUT 3 :
Enter first angle: -30
Enter second angle: 100
Enter third angle: 110
The triangle is not valid.
 

Explanation

  1. The program reads three angle values from the user.
  2. It calculates the sum of the three angles.
  3. If the sum equals 180° and all angles are positive, the triangle is valid.
  4. Otherwise, the triangle is invalid.