C program to find the third angle of a triangle; Through this tutorial, we will learn how to find the third angle of a triangle if two angles are given in c programs.
Programs and Algorithm to Find Third Angle of a Triangle
To find the third angle of a triangle if two angles are given in c programs:
- Algorithm to find third angle of a triangle
- C Program to Find Third Angle of a Triangle
Algorithm to find third angle of a triangle
Use the following algorithm to write a program to find the third angle of a triangle if two angles are given; as follows:
- Input two angles of triangle from user and store it in some variables.
- Compute third angle of triangle using formula
c = 180 - (a + b)
. - Print value of third angle i.e. print c.
C Program to Find Third Angle of a Triangle
/* * Given two angles of a triangle, Here is the * C program to find third angle */ #include <stdio.h> #define ANGLE_SUM 180 int main() { /* Three angles of a triangle */ float a1, a2, a3; /* * Take two angles as input from user */ printf("Enter Two Angles of a Triangle :- "); scanf("%f %f", &a1, &a2); /* Sum of all three angles of a triangle is 180 degrees */ a3 = ANGLE_SUM - (a1 + a2); printf("Third Angle = %0.4f", a3); return 0; }
The output of the above c program; as follows:
Enter Two Angles of a Triangle :- 60 30 Third Angle = 90.0000