本例是实现哥德巴赫猜想,但是出现编译时出现了问题,在此标记
[root@localhost baili]# gcc 18.c -o 18
/tmp/ccl4V3ho.o: In function `main':
18.c:(.text+0xbd): undefined reference to `sqrt'
18.c:(.text+0xcb): undefined reference to `floor'
18.c:(.text+0x11b): undefined reference to `sqrt'
18.c:(.text+0x123): undefined reference to `floor'
collect2: ld returned 1 exit status
我已经包含了头文件 math.h
不知道为什么?
#include <math.h> #include <stdio.h>
int main(int argc, char *argv[]) { int i,j,num; int p,q,flagp,flagq; printf("please intput s plus integer:"); scanf("%d",&num); if(((num%2)!=0)||(num<=4)) printf("input data erro!\n"); else { p=1; do { p = p+1; q = num-p; flagp=1; flagq=1; for(i=2;i<=(int)(floor(sqrt((double)(p))));i++) { if((p%i)==0) { flagp = 0; break; } } j = 2; while (j<=(int)(floor(sqrt((double)(q))))) { if((q%j)==0) { flagq = 0; break; } j++; } }while(flagp*flagq == 0); printf("%d = %d +%d \n",num,p,q); }
}
|
阅读(3962) | 评论(2) | 转发(0) |