In this tutorial you will learn about the C Program to Use Angles to check Triangle is valid or Not and its application with practical example.
C Program to Use Angles to check Triangle is valid or Not
In this tutorial, we will learn to create a C program that will Use Angles to check Triangle is valid or Not in C programming.
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.
- Conditional statements 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.
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 check the Triangle:-
In this tutorial, we will create a program, that will Use Angles to check Triangle is valid or Not. First, we will take three angles from the input by the user. Then we will add all three angles if the sum is equal to 180 then Triangle is valid if not equal to 180 then it’s Not a valid triangle. Then will print the output of the triangle.
180degree equal to sum of all the interior angle of the triangle.
180 = x+y+z
/* C Program to Check Triangle is Valid or Not using Angles */
#include<stdio.h>//Including the header file
int main()//body of the main function.
//declaring the required variable for the program.
int ang1, ang2, ang3, Sum;
//ang1 = it will hold the input angle 1 from the user
//ang2 = it will hold the input angle 2 from the user
//ang3 = it will hold the input angle 3 from the user
//Taking the input angles from the user.
printf("\n Please Enter Three Angles of a Triangle : ");
//Scanning the input angles.
scanf("%d%d%d", &ang1, &ang2, &ang3);
//Calculating the total of all three angles.
Sum = ang1 + ang2 + ang3;
//Checking the triangle
if(Sum == 180)
//Printing the triangle is valid.
printf("\n This is a Valid Triangle");
//Printing the triangle is not valid.
printf("\n This is an Invalid Triangle");
In the above program, we have first initialized the required variable.
- ang1 = it will hold the value for the input first angle of the triangle.
- ang2 = it will hold the value for the input second angle of the triangle.
- ang3 = it will hold the value for the input third angle of the triangle.
Taking the Input of the three angles of the triangle.
Code to check the triangle is a valid triangle or not.
Printing the output for the triangle is valid or not.