📜  检查三角形是等边形,等腰形还是斜角形的程序

📅  最后修改于: 2021-05-04 19:01:56             🧑  作者: Mango

给定XYZ代表三角形的三个边的三个整数,任务是检查给定边形成的三角形是等边的,等腰的还是斜角的。

例子:

方法:请按照以下步骤解决问题:

  1. 检查X = YY = Z。如果发现是真的,则打印“等边三角形”。
  2. 如果不是等边三角形,则检查X = YX = ZY = Z。如果发现是真的,则打印“等腰三角形”。
  3. 如果以上步骤都不满足,请打印“斜角三角形”。

下面是上述方法的实现:

C++
// C++ program for the above approach
#include 
using namespace std;
 
// Function to check if the triangle
// is equilateral or isosceles or scalene
void checkTriangle(int x, int y, int z)
{
     
    // Check for equilateral triangle
    if (x == y && y == z)
        cout << "Equilateral Triangle";
 
    // Check for isoceles triangle
    else if (x == y || y == z || z == x)
        cout << "Isoceles Triangle";
 
    // Otherwise scalene triangle
    else
        cout << "Scalene Triangle";
}
 
// Driver Code
int main()
{
     
    // Given sides of triangle
    int x = 8, y = 7, z = 9;
     
    // Function call
    checkTriangle(x, y, z);
}
 
// This code is contributed by jana_sayantan


Java
// Java program for the above approach
class GFG{
     
// Function to check if the triangle
// is equilateral or isosceles or scalene
static void checkTriangle(int x, int y, int z)
{
 
    // Check for equilateral triangle
    if (x == y && y == z )
        System.out.println("Equilateral Triangle");
 
    // Check for isoceles triangle
    else if (x == y || y == z || z == x )
        System.out.println("Isoceles Triangle");
 
    // Otherwise scalene triangle
    else
        System.out.println("Scalene Triangle");
}
 
// Driver Code
public static void main(String[] args)
{
     
    // Given sides of triangle
    int x = 8, y = 7, z = 9;
     
    // Function call
    checkTriangle(x, y, z);
}
}
 
// This code is contributed by jana_sayantan


Python3
# Python3 program for the above approach
 
# Function to check if the triangle
# is equilateral or isosceles or scalene
def checkTriangle(x, y, z):
 
    # _Check for equilateral triangle
    if x == y == z:
        print("Equilateral Triangle")
 
    # Check for isoceles triangle
    elif x == y or y == z or z == x:
        print("Isoceles Triangle")
 
    # Otherwise scalene triangle
    else:
        print("Scalene Triangle")
 
 
# Driver Code
 
# Given sides of triangle
x = 8
y = 7
z = 9
 
# Function Call
checkTriangle(x, y, z)


C#
// C# program for the above approach
using System;
 
class GFG{
     
// Function to check if the triangle
// is equilateral or isosceles or scalene
static void checkTriangle(int x, int y, int z)
{
 
    // Check for equilateral triangle
    if (x == y && y == z )
        Console.WriteLine("Equilateral Triangle");
 
    // Check for isoceles triangle
    else if (x == y || y == z || z == x )
        Console.WriteLine("Isoceles Triangle");
 
    // Otherwise scalene triangle
    else
        Console.WriteLine("Scalene Triangle");
}
 
// Driver Code
public static void Main()
{
     
    // Given sides of triangle
    int x = 8, y = 7, z = 9;
     
    // Function call
    checkTriangle(x, y, z);
}
}
 
// This code is contributed by code_hunt


Javascript


输出:
Scalene Triangle

时间复杂度: O(1)
辅助空间: O(1)