20分:求C语言的一个命令 可以让用户输入1个字母就退出这个程序的命令!

2025-06-29 05:57:11
推荐回答(3个)
回答1:

根据C的规定,scanf()的返回值:
你可以试着运行下下面这段代码
#include
int main()
{
int m,n;
n=scanf("%d",&m);
printf("%d",n);
}
可以发现当输入数字时,输出1;当输入字母时,输出0;
这样就可以根据scan()的返回值来做出这个命令。

回答2:

char choice;
cout<<"DO you want to continue?\n Please input y to continue, input n to exit.";
cin>>choice;}
while (choice=='y');
return 0;

回答3:

ch=getchar();
if((c>='a' && c<='z') || (c>='A' && c<='Z'))
exit(0);