C Program to Find Third Angle of a Triangle
C
Program to Find Third Angle of a Triangle
·
Write a C program find third angle of triangle.
Required
Knowledge
·
C
printf and scanf functions
·
C Arithmetic
Operators
We will first take two angles of a triangle as input from user
using scanf function. To find the third angle of triangle we
will use below mentioned angle sum property of a triangle.
·
A + B + C = 180
Where
A, B and C are the three internal angles of a triangle.
C
program to find third angle of a triangle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
/*
* 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\n");
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;
}
|
Output
Enter Two Angles of a Triangle
30 60
Third Angle = 90.0000
Comments
Post a Comment