我写的scanf为什么要输入两次?
代码如下 是一个检查质数的代码#include<stdio.h>
int main(void)
{
int num,i;
bool isprime=true;
printf("input a number,enter q to quit.\n");
while(scanf("%d",&num)==1)
{
if(num==1)
printf("1 is not a prime and also not a composite.\n");
else
{
for(i=2;i*i<=num;i++)
{
if(num%i==0)
{
if(i!=num/i)
printf("%d is devisible by %d and %d.\n",num,i,num/i);
else printf("%d is devisible by %d\n",num,i);
isprime=false;
}
}
if(isprime)
printf("%d is a prime\n.",num);
printf("now input another number\n");
scanf("%d",&num);
}
}
printf("Bye\n");
return 0;
}
第一次输入一次即可,但后面就要输入两次才有响应
[ 本帖最后由 chinagdvea 于 2009-11-5 10:56 编辑 ]