我的工作是使用c来证明fermats理论不正确。所以我做的是嵌套循环,它很容易阅读。C语言cygwin编译器,不知道为什么会发生这种情况
这里是代码:
#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);
}
}
编译后,即时得到“试图C =随机数,N = O N总是出于某种原因等于0,即使它永远应该是0
。IM也越来越像 “正确的价值观,以证明费马的理论错为n = 99,C = 500,b = 0,A = 500”
这再次,无论是A,b,C,或n应该是0.不知道是什么问题
是%d是无符号long long int的正确格式说明符... – 2013-03-10 20:50:37
您正在使用未初始化的'a',因为您已经注释了初始化。 – teppic 2013-03-10 20:55:43
我很确定%d是所有整数的正确初始值设定项。 – Alex 2013-03-10 21:00:54