I wrote a small program in C. This program adds the squares of two numbers and checks if the square root of the sum is an integer or not.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 50
int main(int argc, char *argv[])
{
int i,j;
int ar[N][N];
float sq,res;
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
{
ar[i][j]=i*i+j*j;
sq=sqrt(ar[i][j]);
res=sq-(int)sq;
if((res==0) && (i<=j)) {printf("i=%d j=%d and root is %f",i,j,sq);
printf("\n");}
}
printf("\n");
system("PAUSE");
return 0;
}
The program works ok except the last line. It prints:
Code:
i=3 j=4 and root is 5.000000
i=5 j=12 and root is 13.000000
i=6 j=8 and root is 10.000000
i=7 j=24 and root is 25.000000
i=8 j=15 and root is 17.000000
i=9 j=12 and root is 15.000000
i=9 j=40 and root is 41.000000
i=10 j=24 and root is 26.000000
i=12 j=16 and root is 20.000000
i=12 j=35 and root is 37.000000
i=14 j=48 and root is 50.000000
i=15 j=20 and root is 25.000000
i=15 j=36 and root is 39.000000
i=16 j=30 and root is 34.000000
i=18 j=24 and root is 30.000000
i=20 j=21 and root is 29.000000
i=20 j=48 and root is 52.000000
i=21 j=28 and root is 35.000000
i=24 j=32 and root is 40.000000
i=24 j=45 and root is 51.000000
i=27 j=36 and root is 45.000000
i=28 j=45 and root is 53.000000
i=30 j=40 and root is 50.000000
i=33 j=44 and root is 55.000000
i=36 j=48 and root is 60.000000
i=40 j=42 and root is 58.000000
i=50 j=2504 and root is 0.000000
I cannot understand why j=2504!??