I wrote some code in python and C to find solutions for z^2 = x^2 + y^2, x, y and z being all integers. From the python code, which seems to work fine, I know how many solutions there are for some given range. For x and y ranging from 1 to 10000, there should be 14471 unique solutions, or double that, 28942 counting duplicates.
In the following code if I use the ranges from 1 to 1000 for x and y, and set the array solutions to have an appropriate size(2064 in this case) the code works fine. But when I try extend the range of x and y to 1 to 10000, I get a segfault, but don't know why so.
int main()
{
int solutions[28942][2]={0};
int counter = 0;
for(int x=1;x<10000;++x)
{
for(int y=1; y<10000;++y)
{
float z = sqrt(x*x + y*y);
if(z == (int) z)
{
solutions[counter][0] = x;
solutions[counter][1] = y;
++counter;
}
}
}
for(int i = 0;i<28942;++i)
{
printf("This is a solution: {%d,%d}\n",solutions[i][0],
solutions[i][1]);
}
printf("value of counter is %d\n",counter );
}