在C语言下,我想编一个类似如果输入a则输出一句英文;输入b则输出另一句英文的程序,请问怎样编写?

GUIDE1.0.1,MinGW

#include <stdio.h>

int main(void)
{
char ch;
printf("输入q退出。\n")
while(ch!='q')
{
ch = fgetc(stdin);
switch(ch)
{
case 'a':
printf("hello.\n");
break;
case 'b':
printf("world.\n");
break;
default:
break;
}
}
return 0;

简单可扩展的。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-10-27
#include <stdio.h>

main()
{int x;
scanf("%d",&x);
if(x=a) printf("hello!")
else if(x=b) printf("how are you!")
}追问

如果有3条可能甚至更多,还能不能继续编下去呢?

追答

能啊,就是比较麻烦,那你就用上面那位的case就好了,那个可以扩展啊~~~