Find the number of all Pythagoreans within a positive integer N

Find the number of all Pythagorean shares within a positive integer N.

The so-called Pythagorean number refers to three positive integers (a, b, c) that can form the three sides of a right triangle.

#include"stdio.h"

void main()
{
    
    
int n;
int i,j,k; 
int count=0;
while(scanf("%d",&n))
{
    
    
for(i=1;i<=n;++i)
   for(j=i+1;j<=n;++j)
        for(k=j+1;k<=n;++k)
            if(i*i+j*j==k*k)
                {
    
    
                    printf("[%d,%d,%d] ",i,j,k);
                    count++;
                }
printf("total number: %d\n",count);
}
}

First of all, first define a number of Pythagoreans within n, and count means how many Pythagoreans are, and then use the while language to find the three numbers in turn and output them.

Guess you like

Origin blog.csdn.net/m0_54624966/article/details/112982394