If the three sides of a triangle are entered through the keyboard, write a c program to check whether the triangle is isosceles, equilateral, scalene or right angled triangle
Output:
Enter the first side: 3 Enter the second side: 4 Enter the third side: 5 Triangle is right angled Enter the first side: 2 Enter the second side: 2 Enter the third side: 3 Triangle is isosceles. Enter the first side: 3 Enter the second side: 3 Enter the third side: 3 Triangle is equilateral.
- Write a C program to check whether input triangle is equilateral, isosceles or scalene triangle using if else statement.
- A triangle is equilateral triangle, If it's sides are equal.
- A triangle is isosceles triangle, If any two sides of a triangle are equal.
- A triangle is scalene triangle, If none of the sides are equal.
C program to check whether input triangle is equilateral, isosceles or scalene triangle
/* * Write a C program to check whether a Triangle is Equilateral, * Scalene or Isosceles */ #include <stdio.h> int main() { int side1, side2, side3; /* * Take length of three sides of triangle as input * from user using scanf */ printf("Enter Length of Three Sides of a Triangle\n"); scanf("%d %d %d", &side1, &side2, &side3); if((side1 == side2)&&(side2 == side3)) { /* All Sides Equal, Hence Equilateral */ printf("It is an Equilateral Triangle\n"); } else if (side1!=side2 && side2!=side3 && side3!=side1) { /* All sides different, Hence Scelene */ printf("It is a Scalene Triangle\n"); } else { /* Two sides equal, Hence Isoscales */ printf("It is an Isoscales Triangle\n"); } return 0; }Output Enter Length of Three Sides of a Triangle 10 10 10 It is an Equilateral Triangle Enter Length of Three Sides of a Triangle 10 10 5 It is an Isoscales Triangle Enter Length of Three Sides of a Triangle 7 10 5 It is an Isoscales Triangle
Related Topics
Page 2
- Write a C program to enter cost price and selling price and find profit or loss using if else statement.
- C printf and scanf functions
- If Else statement in C
- If Selling Price > Cost Price
Profit = Selling Price - Cost Price - If Selling Price < Cost Price
Loss = Cost Price - Selling Price - If Selling Price = Cost Price
No Profit .. No Loss
Output Enter Cost Price and Selling Price 5 10 Profit = 5 Enter Cost Price and Selling Price 12 8 Loss = 4 Enter Cost Price and Selling Price 10 10 No Profit and No Loss
Related Topics
If the three sides of a Triangle are entered through the keyboard, write a program to check whether the Triangle is isosceles, equilateral, scalene Triangle.
Note:
Equilateral Triangle: A Triangle is called equilateral triangle if length of 3 sides of it are equal.
Example: a = 10, b = 10, c = 10;
Isosceles Triangle: A Triangle is called isosceles triangle if length of 2 sides of it are equal.
Example: a = 5, b = 10, c = 10;
Scalene Triangle: A Triangle is called scalene triangle if length of all 3 sides are different or not equal.
Example: a = 5, b = 6, c = 10;
Output 1:Enter values for a, b and c101010
It’s an Equilateral Triangle
View Discussion
Improve Article
Save Article
Like Article
View Discussion
Improve Article
Save Article
Like Article
Given three integers as X, Y, and Z representing the three sides of a triangle, the task is to check whether the triangle formed by the given sides is equilateral, isosceles, or scalene.
Equilateral Triangle: A triangle is said to be equilateral triangle if all the sides are equal. If X, Y, Z are three sides of the triangle. Then, the triangle is equilateral only if X = Y = Z.
Isosceles Triangle: A triangle is said to be an isosceles triangle if any of its two sides are equal. If X, Y, Z are three sides of the triangle.Then, the triangle is isosceles if either X = Y or X = Z or Y = Z.
Scalene Triangle: A triangle is said Scalene Triangle if none of its sides is equal.
Examples:
Input: X = 6, Y = 8, Z = 10
Output: Scalene Triangle
Explanation:
Since all the sides of the given triangle are unequal, the triangle is scalene.Input: X = 10, Y = 10, Z = 10
Output: Equilateral Triangle
Explanation:
Since all the sides of the given triangle are equal.
Approach: Follow the steps below to solve the problem:
- Check if X = Y and Y = Z. If found to be true, print “Equilateral Triangle”.
- If it is not an Equilateral triangle, then check if X = Y or X = Z or Y = Z. If found to be true, print “Isosceles Triangle”.
- If none of the above steps are satisfied, then print “Scalene Triangle”.
Below is the implementation of the above approach:
#include <bits/stdc++.h> using namespace std; void checkTriangle(int x, int y, int z) { if (x == y && y == z) cout << "Equilateral Triangle"; else if (x == y || y == z || z == x) cout << "Isosceles Triangle"; else cout << "Scalene Triangle"; } int main() { int x = 8, y = 7, z = 9; checkTriangle(x, y, z); } |
class GFG{ static void checkTriangle(int x, int y, int z) { if (x == y && y == z ) System.out.println("Equilateral Triangle"); else if (x == y || y == z || z == x ) System.out.println("Isosceles Triangle"); else System.out.println("Scalene Triangle"); } public static void main(String[] args) { int x = 8, y = 7, z = 9; checkTriangle(x, y, z); } } |
def checkTriangle(x, y, z): if x == y == z: print("Equilateral Triangle") elif x == y or y == z or z == x: print("Isosceles Triangle") else: print("Scalene Triangle") x = 8 y = 7 z = 9 checkTriangle(x, y, z) |
using System; class GFG{ static void checkTriangle(int x, int y, int z) { if (x == y && y == z ) Console.WriteLine("Equilateral Triangle"); else if (x == y || y == z || z == x ) Console.WriteLine("Isosceles Triangle"); else Console.WriteLine("Scalene Triangle"); } public static void Main() { int x = 8, y = 7, z = 9; checkTriangle(x, y, z); } } |
<script> function checkTriangle(x, y, z) { if (x == y && y == z) document.write("Equilateral Triangle"); else if (x == y || y == z || z == x) document.write("Isosceles Triangle"); else document.write("Scalene Triangle"); } let x = 8, y = 7, z = 9; checkTriangle(x, y, z); </script> |
Time Complexity: O(1)
Auxiliary Space: O(1)