1002 Write this number (20 points)
Reads a positive integer n, to calculate the sum of the digits, each digit and write Pinyin.
Input formats:
Each test comprises a test input, i.e. a natural number given value of n. Here guarantee n is less than . 1 0 . 1 0 0 power.
Output formats:
Output on a single line between each one, Pinyin number n of the sum of the digits 1 spaces, but after the last row Pinyin digital with no spaces.
Sample input: 1234567890987654321123456789
Sample output: yi san wu
Code:
#include<stdio.h>
#include<string.h>
int main () {
char num [101]; // n power of 10 up to 100, so creating an array 101 hold the input digital
int a[10];
int n = 0; // Number of request
int t = 0; // sum bits
int i;
char m[][9] ={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
// string must be stored by the two-dimensional array, represents the number of rows, each column represents the maximum number of characters'
gets (num); // use gets () function accepts characters from the keyboard, and then stored in array
for(i=0;i<strlen(num);i++){
n = n + num [i] -48; // determine the total number must be subtracted '0'.
}
while(n!=0){
a[t]=n%10;
n=n/10;
t++;
}
printf("%s",m[a[t-1]]);
for(i=t-2;i>=0;i--){
printf(" %s",m[a[i]]);
}
return 0;
}