Saturday, 21 January 2012

Write a program to find out pythagorean triplets in raange of 1 to 100

#include
#include
#include
void main()
{
 int s1,s2,hyp,ptriple=0;
 clrscr();

 printf(" Side1 ---- side2 ---- hypotenus\n");
 for(s1=0;s1<=100;s1++)
 {
  for(s2=0;s2<=100;s2++)
  {
   for(hyp=1;hyp<=100;hyp++)
   {
   ptriple=(s1*s1)+(s2*s2);
   hyp=hyp*hyp;
   if(hyp==ptriple)
   {
   hyp=sqrt(hyp);
   printf("\n%d ---- %d ---- %d ",s1,s2,hyp);
   }
   }
  }
 }
 getch();
}

No comments:

Post a Comment