write a program to accept three sides of a parameter and check whether it can form a triangle or not.if it form a triangle,check whether it is an acute angled,obtuse angled or right angled triangle.
Answers
Answer:
Explanation:
I am writing it in java
import java.util.Scanner;
class CheckTriangle{
public static void main(String args[]){
int a1,a2,a3;
Scanner obj=new Scanner(System.in);
System.out.println("Enter three sides");
a1=obj.nextInt();
a2=obj.nextInt();
a3=obj.nextInt();
if((a1+a2>a3)&&(a2+a3>a1)&&(a1+a3>a2)){
if(a1!=a2&&a1!=a3&&a2!=a3){
System.out.println("Scalene triangle");
}
else if(a1==a2||a1==a3||a3==a2){
System.out.println("Iscocseles Triangle ");
}
else if((a1==a2)&&(a1==a3)&&(a1==a3)&&(a2==a3)){
System.out.println(" Equilateral Triangle");
}
}
else{
System.out.println("It can't form triangle");
}
}
}
Answer:
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int a,b,c,l;
cout<<"Enter first side of triangle ";
cin>>a;
cout<<"Enter second side of triangle ";
cin>>b;
cout<<"Enter third side of triangle ";
cin>>c;
if(a+b>c && a+c>b && b+c>a)
{
cout<<"Yes triangle can be formed"<<endl;
if(a>=b && a>=c)
{
if(pow(a,2)>pow(b,2)+pow(c,2))
cout<<"It's obtuse angled triangle";
if(pow(a,2)==pow(b,2)+pow(c,2))
cout<<"It's right angled triangle";
if(pow(a,2)<pow(b,2)+pow(c,2))
cout<<"It's acute angled triangle";
}
if(b>=a && b>=c)
{
if(pow(b,2)>pow(a,2)+pow(c,2))
cout<<"It's obtuse angled triangle";
if(pow(b,2)==pow(a,2)+pow(c,2))
cout<<"It's right angled triangle";
if(pow(b,2)<pow(a,2)+pow(c,2))
cout<<"It's acute angled triangle";
}
if(c>=a && c>=b)
{
if(pow(c,2)>pow(a,2)+pow(b,2))
cout<<"It's obtuse angled triangle";
if(pow(c,2)==pow(b,2)+pow(a,2))
cout<<"It's right angled triangle";
if(pow(c,2)<pow(b,2)+pow(a,2))
cout<<"It's acute angled triangle";
}
}
else
cout<<"Triangle can't be formed";
return 0;
}
Explanation:
if a,b,c are sides of triangle and c is longest side then,
if it is a right angle
c^2 = a^2 + b^2
if it is acute
c<a^2 + b^2
if it is obtuse
c> a^2 + b^2
So,find largest side and implement these formulae to check
Hope it helps :-)