0
我已經得到了以下錯誤,我不知道該怎麼辦。我不確定如果我沒有看到一個錯誤的錯字。我在一個網站上發現了這個代碼,並希望在更大的程序中實現它,但我被嚴重卡住了。';'之前的編譯器錯誤(預計')';'令牌)和循環內不打破
test.c: In function ‘main’:
test.c:10:9: error: expected ‘)’ before ‘;’ token
test.c:15:4: error: break statement not within loop or switch
任何幫助將不勝感激。
#include <stdio.h>
int main()
{
int n, i, count=0;
printf ("Enter a positive number: ");
scanf ("%d", &n);
if (i=2; i<=n/2;i++)
{
if(n%i==0) //line 10
{
count++;
break; //line 15
}
return 0;
}
if (count==0 && n!=1)
printf("%d is a prime number",n);
else
printf("%d is not a prime number",n);
return 0;
1,1 Top
}
謝謝你擺脫了錯誤。現在的問題是,如果我輸入一個素數,那麼該程序不會執行任何操作,但非素數會給出正確的結果。 – Bradg89
註釋掉'return 0;'在你的循環中 –
感謝它現在的作品。 – Bradg89