Computer Science, asked by Ashvi16, 1 year ago

WAP to input the sides of a triangle and check whether the triangle is possible or not if possible then display whether it is equilateral isosceles or a scalene triangle otherwise display triangle is not possible


Ashvi16: abbreviation for "write a program"

Answers

Answered by Lipimishra2
6
Here I'm using C++ programming language for writing the program as you've not clearly mentioned any.

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
int a, b, c;
cin >> a >> b >> c;
// check whether a, b, c can form a possible triangle

if (a+b > c && a+c > b && b+c > a)
cout << "The triangle is possible.\n";

// To check whether the triangle is equilateral, isosceles, or scalene.

if (a==b && b==c) // all sides equal
cout << "Equilateral triangle\n";
else if (a==b || a==c || b==c) // at least 2 sides equal
cout << "Isosceles triangle\n";
else // no sides equal
cout << "Scalene triangle\n";

else
cout << "The triangle isn't possible.\n";

return 0;
}

Lipimishra2: Yeah.
Lipimishra2: lemmmee see.
Ashvi16: Am waiting
Ashvi16: Sorry 1st msg was by mistake
Lipimishra2: Ehhh?
Lipimishra2: Kay. I knw java but not sure if the program will work or notttt
Lipimishra2: Why don't you google and find on stackoverflow?
Lipimishra2: I m confusedddddd
Ashvi16: ok
Answered by Anonymous
6
Here's the program in Java:-
import java.util.Scanner;
class tri{
public static void main(String [] args){
Scanner Quan=new Scanner(System.in);
System.out.println("Enter the sides");
int a=Quan.nextInt();
int b=Quan.nextInt();
int c=Quan.nextInt();
if(a+b>c && b+c>a&& c+a>b){
if(a==b && a==c)
System.out.println("IT IS AN EQUILATERAL TRIANGLE");
else if(a==b || b==c || a==c)
System.out.println("IT IS AN ISOSCELES TRIANGLE");
else
System.out.println("IT IS A SCALENE TRIANGLE");
}
else
System.out.println("TRIANGLE NOT PLAUSIBLE");
}
}

Similar questions