c语言编程练习题:7-30 念数字
作者:yunjinqi   类别:    日期:2023-05-29 13:47:42    阅读:469 次   消耗积分: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/155
上一篇:c语言编程练习题:7-29 二分法求多项式单根
下一篇:c语言编程练习题:7-31 掉入陷阱的数字