循環和getchar問題
#include <stdio.h>int main()
{
int a,temp,c;
temp = 0;
printf("請輸入合法數字");
while(48<=(c=getchar())&&c<=57)
{
printf("請輸入合法數字");
a = c-48 ;
a = a + temp;
temp = a ;
}
printf("%d",temp);
}
為什麼我輸入0~9其中一個數字後一次之後,他就不給我輸入,自動跳出
#include <stdio.h>
int main()
{
int a,temp,c;
temp = 0;
printf("請輸入合法數字");
while(48<=(c=getchar())&&c<=57)
{
printf("請輸入合法數字");
a = c-48 ;
a = a + temp;
temp = a ;
while(getchar()!='\n');
}
printf("%d",temp);
}
页:
[1]