Program to accept 3 sides and check if is it of a triangle. If yes, also find type of the triangle.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
float a, b, c, s, tmp, base, h, max;
cout<<"Enter 1st side : ";
cin>>a;
cout<<"Enter 2nd side : ";
cin>>b;
cout<<"Enter 3rd side : ";
cin>>c;
max=a;
base=b;
h=c;
if(b>max)
{
max=b;
base=a;
h=c;
}
else if(c>max)
{
max=c;
base=a;
h=b;
}
s=(a+b+c)/2;
tmp=(s-a)*(s-b)*(s-c)*s;
if(tmp > 0)
{
if(a==b && b==c)
{
cout<<"\nThe given triangle is a equilateral triangle";
}
else if(pow(max,2)==pow(base,2)+pow(h,2))
{
if(a==b || b==c || a==c)
{
cout<<"\nThe given triangle is a isosceles right angled triangle";
}
else if(a!=b && b!=c)
{
cout<<"\nThe given triangle is a scalene right angled triangle";
}
}
else if(a==b || b==c || a==c)
{
cout<<"\nThe given triangle is a isoceles triangle";
}
else if(a!=b && b!=c)
{
cout<<"\nThe given triangle is a scalene triangle";
}
}
else
{
cout<<"\nThe gives sides donot form a triangle.";
}
getch();
}
No comments:
Post a Comment