程序启动后,在控制台中显示“请输入命令:”的提示信息,并等待用户输入内容

读取用户输入的内容,根据用户输入的内容做以下处理: A、用户输入“A”,显示提示“您输入的命令是 A” B、用户输入”B“,显示提示”您输入的命令是 B“ C、用户输入“任意数字”,显示提示“您输入的数字是 (x),该数字的乘积为(y)” D、用户输入“E”,退出程序 E、如果用户输入的内容不是以上命令,显示提示“输入不正确,请重新输入命令”

#include <stdio.h>
int main()
{
char c;
int end=1;
while(end)
{
printf("请输入命令:");
scanf("%s",&c);
switch(c)
{
case 'A':
printf("您输入的命令是“A”\n");break;
case 'B':
printf("您输入的命令是“B”\n");break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
printf("您输入的数字是%c,它的乘积是%d\n",c,(c-'0')*(c-'0'));break;
case 'E':
end=0;break;
default:
printf("输入不正确,请重新输入命令\n");break;
}
}
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-10-17
#include<stdio.h>
#include<math.h>
void main()
{
char cInput;
while (1)
{
fflush(stdin);
printf("Please Input Your Command:\n");
scanf("%c", &cInput);
switch (cInput)
{
case 'A':
printf("Your Command is %c\n", cInput);
break;
case 'B':
printf("Your Command is %c\n", cInput);
break;
case 'E':
exit(1);
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
printf("the number you input is %c\nthe product of the number is (y)\n", cInput);
break;
default:
printf("Input incorrect ,please input again!\n");
}
}
}