| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 655 人关注过本帖
标题:一个不超过10位的数字,要显示每个数字对应英文,程序不知道哪里出错,10位 ...
取消只看楼主 加入收藏
yuchao130
Rank: 2
等 级:论坛游民
帖 子:20
专家分:32
注 册:2014-2-19
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:2 
一个不超过10位的数字,要显示每个数字对应英文,程序不知道哪里出错,10位数字老错
#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;
}




十位数字一下都可以就是不知道为什么每次到十位数字就出错。
找不到问题。。。。
搜索更多相关主题的帖子: include double number count 英文 
2014-02-19 08:29
yuchao130
Rank: 2
等 级:论坛游民
帖 子:20
专家分:32
注 册:2014-2-19
收藏
得分:0 
回复 2楼 rjsp
前两个没问题,第三句话我不是很懂。我刚接触c不到一个月。是说int不能表示这个数字吗? 所以用long int?
2014-02-19 08:58
yuchao130
Rank: 2
等 级:论坛游民
帖 子:20
专家分:32
注 册:2014-2-19
收藏
得分:0 
回复 2楼 rjsp
已解决,谢谢
2014-02-19 09:20
快速回复:一个不超过10位的数字,要显示每个数字对应英文,程序不知道哪里出错, ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011914 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved