Question
Use nested if to check if a triangle is equilateral, isosceles, or scalene.
Solution
✔ Verified
#include <stdio.h>
int main() {
int a, b, c;
printf("Enter three sides of the triangle: ");
scanf("%d %d %d", &a, &b, &c);
if (a + b > c && b + c > a && c + a > b) {
if (a == b && b == c) {
printf("Equilateral triangle\n");
} else if (a == b || b == c || a == c) {
printf("Isosceles triangle\n");
} else {
printf("Scalene triangle\n");
}
} else {
printf("Not a valid triangle\n");
}
return 0;
}
Click here to download practice questions on
If Else StatementMore Questions on If Else Statement
Question 1
Check if a person can vote and also check if they are a senior citizen using nested if.
View solution
Question 7
Write a program in C to Check whether a character is uppercase or lowercase.
View solution
Question 12
Write a program in C to Check if a person is eligible to vote by checking his or her age.
View solution