The length of the three sides are taken as input. Write a C program to find whether a triangle can be formed or not. If not display “This Triangle is NOT possible.” If the triangle can be formed then check whether the triangle formed is equilateral, isosceles, scalene or a right-angled triangle. (If it is a right-angled triangle then only print that it is a Right-angle triangle do not print it as scalene triangle).
The length of the three sides are taken as input. Write a C program to find whether a triangle can be formed or not. If not display “This Triangle is NOT possible.” If the triangle can be formed then check whether the triangle formed is equilateral, isosceles, scalene or a right-angled triangle. (If it is a right-angled triangle then only print that it is a Right-angle triangle do not print it as scalene triangle).
This post covers the topics on Write a C program to find whether a triangle can be formed or not by taking input of the sides, Write a C program to find out which type of triangle is this by taking the sides as input
In the following program, we have used multiple If else statement that is nested if-else. You need to under the concept of if-else first in order to understand the following program. You should check out this post.
In the following code at first, we declare the sides i.e a,b,c and take the input and store the value in a,b,c using scanf () function. Again we declare three variable big, secondbig, small.
Then check the condition of if statement if the condition is true then the body of if statement will execute otherwise it will go on the else part and so on and so for.Write a C program to check whether a triangle is equilateral, isosceles, scalene or a right-angled triangle.
- #include<stdio.h>
- int main()
- {
- int a,b,c;
- scanf("%d %d %d",&a, &b, &c); /*The length of three sides are entered */
- int big,secondbig,small;
- if(a>=b&&a>=c)
- {big=a;
- if(b>=c)
- {secondbig=b;
- small=c;}
- else
- {secondbig=c;
- small=b;}
- }
- else if(b >= a&&b >= c)
- {big=b;
- if(a>=c)
- {secondbig=a;
- small=c;}
- else
- {secondbig=c;
- small=a;}
- }
- else
- { big=c;
- if(b>=a)
- {
- secondbig=b;
- small=a;
- }
- else
- {
- secondbig=a;
- small=b;
- }
- }
- if(secondbig+small>big)
- {
- if(secondbig*secondbig + small*small ==big*big)
- printf("Right-angle Triangle");
- else if((a==b&&a!=c)||(a==c&&a!=b)||(c==b&&c!=a))
- printf("Isosceles Triangle");
- else if((a!=b&&a!=c)&&(b!=c))
- printf("Scalene Triangle");
- else
- printf("Equilateral Triangle");
- }
- else
- printf("Triangle is not possible");
- return 0;
- }
0 Comments