C program to find the third angle of a triangle :
In this tutorial, we will learn how to find the third angle of a triangle if the first and second angle is given. We know that the sum of all three angles of a triangle is 180 degree. So, to find the third angle, we will subtract the sum of two angles from 180. Let’s take a look at the program :
C Program code :
#include
#define SUM 180
int main(){
//1
float firstAngle,secondAngle,thirdAngle;
//2
printf("Enter first and second angle of the triangle : ");
scanf("%f %f",&firstAngle,&secondAngle);
//3
thirdAngle = SUM - (firstAngle + secondAngle);
//4
printf("You have entered %f and %f\n",firstAngle,secondAngle);
printf("Third Angle is : %f \n",thirdAngle);
}
Explanation :
_The commented numbers above indicate the steps number below :_
- First, create three float variables to store all three angles.
- Ask the user to enter the first and second angle of the triangle. And store it in variables firstAngle and secondAngle.
- Now, calculate the third angle and store the value in variable thirdAngle.
- Print all angles: firstAngle,secondAngle and thirdAngle
Sample Outputs :
Enter first and second angle of the triangle : 120 30
You have entered 120.000000 and 30.000000
Third Angle is : 30.000000
Enter first and second angle of the triangle : 20
30
You have entered 20.000000 and 30.000000
Third Angle is : 130.000000
Enter first and second angle of the triangle : 13.5
12.5
You have entered 13.500000 and 12.500000
Third Angle is : 154.000000