c语言的定义Y/N按Y继续按N退出怎么弄
c语言的定义Y/N按Y继续按N退出怎么弄
为啥这样可以:
#include <stdio.h>
int main(void)
{
int i,flag = 1;
int a;
while(flag == 1)
{
flag = 0;
scanf("%d",&i);
printf("%d\n",i);
printf("是否继续1/0\n");
scanf("%d",&a);
if(a == 1)
flag = 1;
}
return 0;
}
这样就不行:
#include <stdio.h>
int main(void)
{
int i,flag = 1;
char a;
while(flag == 1)
{
flag = 0;
scanf("%d",&i);
printf("%d\n",i);
printf("是否继续y/n\n");
scanf("%c",&a);
if(a == 'y')
flag = 1;
}
return 0;
}