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:

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:

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.
Go to:
PREV : Triangle Type Determination.
NEXT : Character Type Classification.
C Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
