- In this program, we declare three float variables
angle1,angle2, andangle3. We useprintf()andscanf()to get the values of the first two angles from the user. - We then calculate the value of the third angle using the formula
angle3 = 180 - (angle1 + angle2)since the sum of the angles in a triangle is always 180 degrees. - Finally, we print out the value of the third angle using
printf(). Note that we use the%fformat specifier to print out the floating point value of the angle.
#include <stdio.h>
int main() {
float angle1, angle2, angle3;
// Get the first two angles from the user
printf("Enter the first angle of the triangle: ");
scanf("%f", &angle1);
printf("Enter the second angle of the triangle: ");
scanf("%f", &angle2);
// Calculate the third angle
angle3 = 180 - (angle1 + angle2);
// Print the third angle
printf("The third angle of the triangle is %f degrees\n", angle3);
return 0;
}
OUTPUT
Enter the first angle of the triangle: 60
Enter the second angle of the triangle: 70
The third angle of the triangle is 50.000000 degrees
