Monday, 22 December 2014

C++ PROGRAM TO FIND PHYTHAGOREAN TRIPLE


A set of integers a, b and c is called Pythagorean triple if a2 + b2 = C2, for example, the integers 3, 4 and 5 from a Pythagorean triple because 32 +  42 = 52 Write program to find Pythagorean triple using object-oriented approach.

SOLUTION:

#include<stdio.h>
#include<iostream.h>
#include<conio.h>

class pythagorus
{
int a,b,c;
  public:
void getdata();
void check();
};
void pythagorus::getdata()
{
  cout<<"enter three sides of a triangle:"<<endl;
  cin>>a>>b>>c;
}

void pythagorus::check()
{
  int a1,a2,b1,b2,c1,c2;
  if(a>b&&a>c)
  {
      a1=a*a;
      a2=(b*b)+(c*c);
      if (a1=a2)
      {
       cout<<"the triplets are forming pythagous theorem."<<endl;
       cout<<"the hypotenuese is:"<<a;
      }
      else
cout<<"invalid inputs."<<endl;
   }
  else if(b>a&&b>c)
  {
      b1=b*b;
      b2=(a*a)+(c*c);
      if (b1==b2)
      {
       cout<<"the triplets are forming pythagous theorem."<<endl;
       cout<<"the hypotenuese is:"<<b;
      }
      else
cout<<"invalid inputs."<<endl;
  }
  else if(c>a&&c>b)
  {
c1=c*c;
c2=(a*a)+(b*b);
if (c1==c2)
{
cout<<"the triplets are forming pythagous theorem."<<endl;
cout<<"the hypotenuese is:"<<c;
      }
      else
cout<<"invalid inputs."<<endl;
  }
}
void main()
{
    clrscr();
    pythagorus pyth;
    pyth.getdata();
    pyth.check();
    getch();
}

OUTPUT:

No comments:

Post a Comment