在控制台输入一个正整数,将每一位上的0-9数字映射为字符a-j,然后将字符输出到控制台,比如标准输入1031,输出bacb
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main(){
int number,val;
int counter = 1;
int *p = NULL;
scanf("%d",&number);
val = number;
while(val/10){
counter++;
val /= 10;
}
while(counter != 0){
p = (int *)malloc(sizeof(1)*counter);
*p = number/fab(counter);
printf("%c",(*p)+97);
number = number-(*p)*fab(counter);
p++;
counter--;
}
free(p);
return 0;
}
int fab(int n){
int i;
int result = 1;
for(i = 1;i < n;i++)
result *= 10;
return result;
}
新手刚写程序,请大神们帮忙优化一下,求交流