|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<string.h>
int main()
{
unsigned long long int i;
int count=0,j,d=0;
int k[10];
char ch[10];
scanf("%lld",&i);
while(i!=0)
{
count=count+i%10;
i=i/10;
}
d=0;
while(count!=0)
{
k[d]=count%10;
d++;
count=count/10;
}
k[d]='\0';
j=d-1;
for(j;j>=0;j--)
{
switch(k[j])
{
case 1:strcpy(ch,"yi");break;
case 2:strcpy(ch,"er");break;
case 3:strcpy(ch,"san");break;
case 4:strcpy(ch,"si");break;
case 5:strcpy(ch,"wu");break;
case 6:strcpy(ch,"liu");break;
case 7:strcpy(ch,"qi");break;
case 8:strcpy(ch,"ba");break;
case 9:strcpy(ch,"jiu");break;
case 0:strcpy(ch,"ling");break;
}
printf("%s ",ch);
}
return 0;
}
你要看清楚,n小于 10的100次方
你能告诉我 unsigned long long 的取值范围吗?
- #include <stdio.h>
- int main(void) {
- const char *string[] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
- int ch;
- size_t sum = 0;
- while((ch = getchar()) != '\n') {
- if(ch == EOF) break;
- sum += ch - '0';
- }
- size_t reverse = 0;
- while(sum) {
- reverse = reverse * 10 + (sum % 10);
- sum /= 10;
- }
- ch = '\0';
- while(reverse) {
- printf("%c%s", ch, string[reverse % 10]);
- ch = ' ';
- reverse /= 10;
- }
- printf("\n");
- return 0;
- }
复制代码
|
-
|