分析:
需要注意到 n 的范围在0~10的一百次方,我们通常用来表示整数的 int 与 long 都不能满足如此大的整数值要求
所以我们需要转换思路,只能一个一个的存数字了,可以考虑直接用一个字符串来存输入的数字
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char num[101] = {0};
int sum = 0;
int i;
char *temp = num;
char *hanzi[] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
char num_str[4] = {0};;
scanf("%s",&num);
while(*temp != '\0')
{
sum += (*temp - '0');
temp++;
}
sprintf(num_str,"%d",sum);
i = 0;
while(num_str[i]!='\0')
{
if(num_str[i+1] == '\0')
printf("%s\n",hanzi[(num_str[i]-'0')]);
else
printf("%s ",hanzi[(num_str[i]-'0')]);
i++;
}
return 0;
}