find pythagorean triplets

#include<stdio.h>
void pytriplets(int);
int main()
{
    int limit;
    scanf("%d",&limit);
    pytriplets(limit);
    return 0;
}
void pytriplets(int limit)
{
    int a,b,c=0,n;
    int m=2;
    while(c<limit)
    {
     for(n=1;n<m;n++)
     {
         a=m*m-n*n;
         b=2*m*n;
         c=m*m+n*n;
   
   
     if(c>limit)
        break;
        printf("%d %d %d\n",a,b,c);
     }
     m++;
   
   
    }
   
}
input:
10
output
3 4 5
8 6 10

No comments:

Post a Comment