C Exercises: Check whether a triangle can be formed by given value
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](https://www.w3resource.com/w3r_images/c-conditional-statement-image-exercises-15.png)
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.
}
}
Sample 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](https://www.w3resource.com/w3r_images/c-conditional-statement-exercise-15.png)
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics