C Exercises: Find the third angle of a triangle if two are given
Write a C program to find the third angle of a triangle if two angles are given.
Pictorial Presentation:
Sample Solution:
C Code:
#include <stdio.h>
int main()
{
int ang1, ang2, ang3; /*are three angles of a triangle */
/* Read two angles of the triangle from user separated by comma*/
printf("Input two angles of triangle separated by comma : ");
scanf("%d, %d", &ang1, &ang2);
ang3 = 180 - (ang1 + ang2); /* Calculates the third angle */
printf("Third angle of the triangle : %d\n", ang3);
return 0;
}
Sample Output:
Input two angles of triangle separated by comma : 50,70 Third angle of the triangle : 60
Flowchart:
C Programming Code Editor:
Previous: Write a C program to perform addition, subtraction, multiplication and division of two numbers.
Next: C Conditional Statement Exercises Home
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