/**
* C program to find all angles of a triangle if two angles are given
*/
#include <stdio.h>
int main()
{
int a, b, c;
/* Input two angles of the triangle */
printf("Enter two angles of triangle: ");
scanf("%d%d", &a, &b);
/* Compute third angle */
c = 180 - (a + b);
/* Print value of the third angle */
printf("Third angle of the triangle = %d", c);
return 0;
}
Enter two angles of triangle: 60 30
Third angle of the triangle = 90
Arithmetic operators, Data types, Basic input/output
Sum of angles of a triangle is 180°.
Let us apply basic math to derive formula for third angle. If two angles of a triangle are given, then third angle of triangle is given by -
Step by step descriptive logic to find third angle of a triangle -
c = 180 - (a + b).First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.