In this tutorial you will learn about the C Program to Find Angle of a Triangle if two angles are given and its application with practical example.
C Program to Find Angle of a Triangle if two angles are given
In this tutorial, we will learn to create a C program that will Find the third Angle of a Triangle in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Arithmetic Operations in C Programming.
What is a triangle?
In geometry, a triangle is a shape generally to be drawn by three lines. The triangle has three interior angles and the total of its interior angle is 180 degrees.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input two angles of the triangle. 3. Calculating the of <strong>third angle</strong> of the triangle using the code. 4. Printing the third angle of a triangle. 5. End the program. |
Program description that will print the area of a Triangle:-
In this tutorial, we will create a program, that will find the angle of a triangle using C programming. First, take the input angle 1 and 2 of the triangle by the user. Then we will find the third angle using the arithmetic expression. At last, we will print the answer third angle.
1 2 3 4 5 |
Here, 180degree equal to sum of all the interior angle of the triangle. 180 = x+y+z z=180-(x+y) |
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/** * C program to find all angles of a triangle if two angles are given */ #include <stdio.h>//including the header file int main()//Body of the amin function { //declaring the required variables for the program. int x, y, z; //x,y,z = it will hold the intger value for the angles of the triangle. /* Taking Input two angles of the triangle */ printf("Enter two angles of triangle: "); scanf("%d%d", &x, &y);//Scanning the two angles of the triangle. /* Computing the third angle */ z = 180 - (x + y); /* Print value of the third angle of the triangle*/ printf("Third angle of the triangle = %d", z); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- x = it will hold the value for the input first angle of the triangle.
- y = it will hold the value for the input second angle of the triangle.
- z = it will hold the value for the third angle of the triangle.
Taking the Input the first and the second angle of the triangle.
Code to calculate the third angle of the triangle.
Printing output the third angle of the triangle.