1. 程式人生 > >將數字轉換成對應的漢語拼音

將數字轉換成對應的漢語拼音

// 群裡一小盆友問的,輸入數字-100000~100000之後轉換成對應的“yi er san 。。。”中間用空格隔開,最後沒有空格

//思路一:取出每一位數字新的陣列,最後倒序輸出

#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
	int i,j=0,n;
	char *pin[]={"ling","yi","er","san","si","wu","lv","qi","ba","jiu"};
	int data[6];

	printf("請輸入一個整數>>> ");
	scanf("%ld",&n);

	if(n<0)
		printf("fu ");
	n = abs(n); //取絕對值
	do
	{
		data[j++] = n%10;
		n = n/10;
	}while(n);

	for(i=j-1;i>0;i--)
	{
		printf("%s ",*(pin+data[i]));
	}
	printf("%s\n",*(pin+data[0]));

	return 0;
}