【C语言】PAT 1002 读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字
作者:互联网
#include <stdio.h>
int main()
{
char ch;
int sum=0;
ch = getchar();
while (ch != '\n')
{
sum+=ch-'0';
ch = getchar();
}
int i,s[9];
for(i=0;sum;)
{
s[i++]=sum%10;
sum=sum/10;
}
i--;
while(i>=0)
{
switch(s[i--])
{
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");
}
if(i>=0)
printf(" ");
}
return 0;
}
标签:case,ch,数字,int,sum,C语言,break,读入,printf 来源: https://blog.csdn.net/yi_zhi_xiao_qi_e/article/details/123252412