程式碼如下,為何ce?在我家執行一切正常。
#include <stdio.h>
#define N 1000000
int main()
{
bool primer[N]={0};
int p[78498];
long i,j,cc=0;
for(i=2;i<N;i++){
if(primer[i] == 1){
continue;}else{p[cc]=i;cc++;}
for(j=i+i;j<N;j=j+i)
primer[j]=1;
}
long n,ch;
while(scanf("%d",&n)!=EOF){
if(n == 0)
break;
ch=0;
for(i=0;i<78498;i++){
if(primer[n-p[i]]==0){printf("%d = %d + %d\n",n,p[i],n-p[i]);ch++;break;}
}
if(ch==0){printf("Goldbach's conjecture is wrong.\n");}
}
return 0;
}
看了編譯回傳的結果
編譯錯誤,請檢查語法是否符合系統(ANSI/ISO C/C++ by GNU)的要求。
錯誤訊息:
/tmp/code_11706.c: In function `main':
/tmp/code_11706.c:6: error: `bool' undeclared (first use in this function)
/tmp/code_11706.c:6: error: (Each undeclared identifier is reported only once
/tmp/code_11706.c:6: error: for each function it appears in.)
/tmp/code_11706.c:6: error: parse error before "primer"
/tmp/code_11706.c: At top level:
/tmp/code_11706.c:9: error: parse error before "for"
/tmp/code_11706.c:13: error: conflicting types for 'j'
/tmp/code_11706.c:8: error: previous declaration of 'j' was here
/tmp/code_11706.c:13: error: initializer element is not constant
/tmp/code_11706.c:13: error: parse error before ')' token
/tmp/code_11706.c:19: error: parse error before "while"
/tmp/code_11706.c:22: error: conflicting types for 'ch'
/tmp/code_11706.c:17: error: previous declaration of 'ch' was here
/tmp/code_11706.c:22: warning: data definition has no type or storage class
/tmp/code_11706.c:23: error: parse error before "for"
解題語言改用C++就會過了
看了編譯回傳的結果
編譯錯誤,請檢查語法是否符合系統(ANSI/ISO C/C++ by GNU)的要求。
錯誤訊息:
/tmp/code_11706.c: In function `main':
/tmp/code_11706.c:6: error: `bool' undeclared (first use in this function)
/tmp/code_11706.c:6: error: (Each undeclared identifier is reported only once
/tmp/code_11706.c:6: error: for each function it appears in.)
/tmp/code_11706.c:6: error: parse error before "primer"
/tmp/code_11706.c: At top level:
/tmp/code_11706.c:9: error: parse error before "for"
/tmp/code_11706.c:13: error: conflicting types for 'j'
/tmp/code_11706.c:8: error: previous declaration of 'j' was here
/tmp/code_11706.c:13: error: initializer element is not constant
/tmp/code_11706.c:13: error: parse error before ')' token
/tmp/code_11706.c:19: error: parse error before "while"
/tmp/code_11706.c:22: error: conflicting types for 'ch'
/tmp/code_11706.c:17: error: previous declaration of 'ch' was here
/tmp/code_11706.c:22: warning: data definition has no type or storage class
/tmp/code_11706.c:23: error: parse error before "for"
解題語言改用C++就會過了
上面的編譯錯誤說明了 C 語言沒有定義 bool
很怪吧,純 C 裡就用整數 0 or 1來 處理 boolean 吧
用純 C 寫 連 // 這種註解符號都不行哦...