我正在嘗試爲一個類製作一個簡單的C程序,其中一個要求是我需要爲所有輸入和輸出使用scanf
/printf
。我的問題是爲什麼我的主循環中的scanf
跳過並且程序剛剛終止。scanf正在跳過
這裏是我的代碼
#include <stdio.h>
void main() {
int userValue;
int x;
char c;
printf("Enter a number : ");
scanf("%d", &userValue);
printf("The odd prime values are:\n");
for (x = 3; x <= userValue; x = x + 2) {
int a;
a = isPrime(x);
if (a = 1) {
printf("%d is an odd prime\n", x);
}
}
printf("hit anything to terminate...");
scanf("%c", &c);
}
int isPrime(int number) {
int i;
for (i = 2; i < number; i++) {
if (number % i == 0 && i != number)
return 0;
}
return 1;
}
我能夠通過第一個後加入另一相同scanf
「修復」,但我寧願只使用一個。
你試過'系統(「暫停」);'? –
是直接C還是隻有C++? –
Staight c。注意缺少名稱空間? –