读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:
给出自然数 n 的值。这里保证 n 小于 10^100。
输出格式:
在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。
#include <stdio.h>
int sum(void);
void print_py(int);
int main() {
print_py(sum());
return 0;
}
void print_py(int a)
{
static char const * py[] ={ "ling","yi","er","san","si",
"wu","liu","qi","ba","jiu" };
if( a > 0)
{
print_py(a/10);
printf("%s%s", a<10 ? "" : " " , py[a%10] );
}
}
int sum(void)
{
char ch;
int count =0;
while( (ch=getchar()) !='\n' ){
//ch - '0'一般就是把一个数字字符的ASCII值变成对应的字符的值
count=count+ch-'0';
}
return count;
}