一个不超过10位的数字,要显示每个数字对应英文,程序不知道哪里出错,10位数字老错

本文介绍了一个使用C语言编写的程序,该程序能够将输入的整数转换为英文描述形式,例如将数字123转换为one-two-three。程序通过循环计算每位数字并将其映射为对应的英文单词来实现这一功能。

#include<stdio.h>
#include<math.h>

int main(void)
{
     int a,x,number,y,z,j;
     float b;
     double m,n;
     long int i;
     printf("Please enter a number but no larger than 10 digits:");
     scanf_s("%d",&a);
     number=0;
     n=10;

     for (i=1;i<=a;i=i*10)//count number of digitals 
     {
         number=number+1;
     }
     z=number;

     for (j=z;j>0;j--)
     {   
         m=j-1;
         x=pow(n,m);
         b=a/x;
         y=(int)b;
         switch (y)
     {
        case 0: // if y=0
            printf("zero"); // print zero
            break; // terminate
        case 1: // if y=1
            printf("one"); // print one
            break; // terminate
        case 2: // if y=2
            printf("two"); // print two
            break; // terminate
        case 3: // if y=3
            printf("three"); // print three
            break; // terminate
        case 4: // if y=4
            printf("four"); // print four
            break; // terminate
        case 5: // if y=5
            printf("five"); // print five
            break; // terminate
        case 6: // if y=6
            printf("six"); // print six
            break; // terminate
        case 7: // if y=7
            printf("seven"); // print seven
            break; // terminate
        case 8: // if y=8
            printf("eight"); // print eight
            break; // terminate
        case 9: // if y=9
            printf("nine"); // print nine
            break; // terminate
         }
            a=a-y*x;
            if (j>1)
                printf("-");
            else 
                printf(" ");
            
     }
     printf("\n");
     return 0;
}

十位数字一下都可以就是不知道为什么每次到十位数字就出错。我真的找不到问题,你有帮我看看问题在哪里吗?谢谢了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值