Reputation: 73
My job is to prove fermats theory incorrect using c. so what i did was have nested loops, its pretty easy to read.
here is the code:
#include <stdio.h>
#include <math.h>
quadtest(unsigned long long int a, unsigned long long int b, unsigned long long int c, unsigned int n)
{
if ((pow(a,n)+pow(b,n))==pow(c,n))
return 1;
else
return 0;
}
main()
{
unsigned long long int a;
unsigned long long int b;
unsigned long long int c;
unsigned int n;
//a=1; b=1; c=1; n=1;
for(n=2; n<100; n++)
{
printf("\nn=%d",n);
for(c=1; c<500; c++)
{
printf("\ntrying now c=%d and n=%d",c,n);
for(b=1; b<500; b++)
{
if (quadtest(a,b,c,n)) break;
//printf("\nb=%d, n=%d",b,n);
}
for(a=1; a<500; a++)
{
if (quadtest(a,b,c,n)) break;
//printf("\na=%d, n=%d",a,n);
}
}
printf("\nthe right values to prove fermats theory wrong are n=%d,c=%d,b=%d,a=%d",n,c,b,a);
}
}
after being compiled, im getting "trying c=random number, n=0. n always equals 0 for some reason even though its never supposed to be 0.
im also getting something like "the right values to prove fermats theory wrong are n=99,c=500,b=0,a=500"
which once again, neither a, b, c, or n are supposed to be 0. not sure what the problem is
Upvotes: 0
Views: 101
Reputation: 8195
There are two clear problems with your code:
You define several variables, and each is initialised except for a
. You call a function using a
uninitialised. This is undefined behaviour and could explain your problem.
Secondly, you are using the incorrect specifier in printf
. %d
is used for int
; %llu
is for unsigned long long
. Using the wrong specifier can lead to incorrect values being output.
Upvotes: 1