写完数据敲了回车之后程序直接结束,没有结果
课程设计
1
我想用代码写出读出数字的拼音,这个代码输入了数据之后直接就结束了,没有结果,为啥
# include<stdio.h>
int main()
{
char c;
while((c = getchar())!='\n')
{
switch(c)
{
case 0:printf("ling");
case 1:printf("yi");
case 2:printf("er");
case 3:printf("san");
case 4:printf("si");
case 5:printf("wu");
case 6:printf("liu");
case 7:printf("qi");
case 8:printf("ba");
case 9:printf("jiu");
case '-':printf("fu");
}
}
return 0;
}
-
#include <stdio.h> int main() { char c; while ((c = getchar()) != '\n') { switch (c) { case '0': printf("ling"); break; case '1': printf("yi"); break; case '2': printf("er"); break; case '3': printf("san"); break; case '4': printf("si"); break; case '5': printf("wu"); break; case '6': printf("liu"); break; case '7': printf("qi"); break; case '8': printf("ba"); break; case '9': printf("jiu"); break; case '-': printf("fu"); break; } } return 0; }
-
# include<stdio.h> int main() { char c; while ((c = getchar()) != '\n') { switch (c) { case '0':printf("ling"); break; case '1':printf("yi"); break; case '2':printf("er"); break; case '3':printf("san"); break; case '4':printf("si"); break; case '5':printf("wu"); break; case '6':printf("liu"); break; case '7':printf("qi"); break; case '8':printf("ba"); break; case '9':printf("jiu"); break; case '-':printf("fu"); break; } } return 0; }
char c;//c是字符类型的数据,getchar读入的也是字符,所以在判断时应该作字符判断,同时在每次case判断后要加break跳出switch
发表回复