w3resource

C Exercises: Check whether a triangle can be formed by given value


15. Triangle Validity by Angles

Write a C program to check whether a triangle can be formed with the given values for the angles.

Visual Presentation:

Check whether a triangle can be formed by given value


Sample Solution:

C Code:

#include <stdio.h>  // Include the standard input/output header file.

void main()  
{  
    int anga, angb, angc, sum; // Declare variables for the angles of the triangle.

    printf("Input three angles of triangle : ");  // Prompt user for input.  
    scanf("%d %d %d", &anga, &angb, &angc);  // Read and store the angles of the triangle.

    /* Calculate the sum of all angles of triangle */  
    sum = anga + angb + angc;   

    /* Check whether sum=180 then its a valid triangle otherwise not */  
    if(sum == 180)   
    {  
        printf("The triangle is valid.\n");  // Print message for valid triangle.
    }  
    else  
    {  
        printf("The triangle is not valid.\n");  // Print message for invalid triangle.
    }  
 } 

Output:

Input three angles of triangle : 40 55 65                                                                     
The triangle is not valid.

Flowchart:

Flowchart: Check whether a triangle can be formed by given value


For more Practice: Solve these Related Problems:

  • Write a C program to check if three given angles can form a triangle and output an error if they do not.
  • Write a C program to validate triangle angles using only arithmetic operations without conditional statements.
  • Write a C program to check triangle validity with angles and compute the area using trigonometric formulas if valid.
  • Write a C program to accept three angles, verify triangle validity, and then output the triangle’s classification based on its angles.

C Programming Code Editor:



Previous: Write a C program to check whether a triangle is Equilateral, Isosceles or Scalene.
Next: Write a C program to check whether a character is an alphabet, digit or special character.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.