在這獻上修改過的程式,內附解釋為何這樣修改,如還有不清楚在提問,我會竟量回答!!!! #include <stdio.h>
#include <stdlib.h>//記得加這個,程式的畫面才會停止
int fun(int y) { //判斷y是不是素數(質數) {
int i,b;
for(i = 2;i <= /*(int)*/(y/2);i++){ // 第一這裡的"(int)"是多餘的!!!!
if(y % i == 0){ //不是素數!!
// b = 0; 這也不需要," 為什麼 "下面會解釋!!!!!!
return 0;//使待會的fun(s)的s=0也就是不成立!!!!!
}
}
// if(b != 0) 第二(!!!!!!很重要!!!!!!!!)你的b何時不等於" 0 " !!!,你沒寫所以乾脆不要寫這個判斷式
return 1;//是素數,使s=1也就是成立!!!!
}
int main(){
int x = 10000, s;
/* printf("輸入數字: ");
scanf("%d",&x); 需要判斷玩家輸入時才加入 */
for(s = 2; s <= x; s++){
if(fun(s) == 1) //确定s是不是素?,是?1,???
printf("%d ",s);
}
system("pause");//這是對應上方的#include <stdlibo.h>
return 0;
}
大致在解釋二樓為何這樣改,同時加入一些個人建議!!
不知道是否解決您的問題,同時也請您找出最佳解答!!感謝 
繼續努力學習吧魚油!!!! |