L1-007 念数字 (10 分)

使用二维字符数组
然后把数字进行数位分解

#include
int main(){
	int num;
	char str[][10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
	scanf("%d",&num);
	if(num<0) {
		printf("fu ");
		num=-num;
	}
	int arr[15],k=0;
	do{
		arr[k++]=num%10;
		num/=10;
	}while(num!=0);
	for(int i=k-1;i>=0;i--){
		if(i==k-1){
			printf("%s",str[arr[i]]);
		}else{
			printf(" %s",str[arr[i]]);
		}
	}
	return 0;
} 

你可能感兴趣的:(字符串)