c语言编程练习题:7-153 念数字
作者:yunjinqi   类别:    日期:2023-05-31 17:47:15    阅读:241 次   消耗积分:0 分    

image.png

#include <stdio.h>
#include <math.h>
int main(){
    char my_string[][5] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu",};
    // int n = pow(10,2);
    // printf("v:%d",n);
    int num;
    int count=1;
    if (scanf("%d",&num)!=0){
        if (num<0){num=-1*num;printf("fu");count=count+1;}
        if (num==0){printf("ling");count=count+1;}
        if (num>0){
            int i;
            int new_num = num;
            for (i=-1;new_num!=0;i++){
                new_num = new_num/10;
            }
            //printf("%d",i);
            while (i>=0){
                if (num>0){
                    int v = pow(10,i)+0.01;
                    // printf("i = %d pow(10,i) = %d\n",i,v);
                    new_num = num/v;
                    if (count == 1){printf("%s",my_string[new_num]);count=count+1;}
                    else{printf(" %s",my_string[new_num]);count=count+1;}
                    num = num % v;
                    //printf("test i:%i v:%d new_num:%d num:%d string:%s\n",i,v,new_num,num,my_string[new_num]);
                    i = i-1;
                }else{
                    printf(" ling");
                    i = i-1;
                    count=count+1;
                }
                
            }
        }
    }else{
        printf("something wrong");
    }
    return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/278
上一篇:c语言编程练习题:7-152 考试座位号
下一篇:c语言编程练习题:7-154 求整数段和