"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Wednesday, February 3, 2010

WAP to find the Pythagorean triples between 1 to 100.


A Pythagorean triple consists of three positive integers a, b, and c,
such that a2 + b  = c2 . Such a triple is commonly written (a, b, c), and a well-known example is (3, 4, 5).

There are 16 primitive Pythagorean triples with c ≤ 100:
( 3, 4, 5) ( 5, 12, 13) ( 7, 24, 25) ( 8, 15, 17)


( 9, 40, 41) (11, 60, 61) (12, 35, 37) (13, 84, 85)


(16, 63, 65) (20, 21, 29) (28, 45, 53) (33, 56, 65)


(36, 77, 85) (39, 80, 89) (48, 55, 73) (65, 72, 97)


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

void main()
{
int side1, side2, hyp;
cout<< " \n Pythagorean triples between 1 to 100 :\n\n ";
for( side1 = 1; side1< =100 ; side1 ++)
  for( side2 = 1; side2< =100 ; side2 ++)
      for( hyp = 1; hyp< =100 ; hyp ++)
              if((side1*side1 + side2*side2) = = hyp * hyp )
                 cout<< "\n"<< "(" side1 << "\t" << side2 << "\t" << hyp <<  ")";
 
getch();
}

4 comments:

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.