PTA——念数字

时间:2022-02-24 07:03:35

程序:

 #include<stdio.h>
#include<stdlib.h>
#define N 50 int main() {
char pinyin[][] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
int memory[N] = {};
int n,t,i = ,minus = ;
scanf("%d",&n);
if(n==) printf("ling");
if(n<) {
minus = ;
n = -n;
}
if(n>) {
while(n!=) {
t = n%;
n /= ;
memory[i] = t;
i++;
}
i--;
if(minus == ) printf("fu ");
for(; i>; i--) {
printf("%s ",pinyin[memory[i]]);
}
printf("%s",pinyin[memory[i]]);
}
return ;
}

数组存储字符和每位数字,用循环实现倒序输出