C Exercises: Check whether a triangle can be formed by given value
C Conditional Statement: Exercise-15 with Solution
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.
}
}
Sample Output:
Input three angles of triangle : 40 55 65 The triangle is not valid.
Flowchart:
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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/c-programming-exercises/conditional-statement/c-conditional-statement-exercises-15.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics