| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 438 人关注过本帖
标题:哪位来看看出啥问题了。。。。
只看楼主 加入收藏
qq393825817
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2011-11-10
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:2 
哪位来看看出啥问题了。。。。
#include<stdio.h>
void main()
{
    void trans(float n);
    float n;
    scanf("%f",&n);
    int p;
    p=(int)n;   //为啥这里不能把float转化为int类型的,该怎么改?我这个程序想把输入转化为英语。小数点后面程序不用!!就是求助这里为啥不能转化!!!//
    trans(p);
}
void trans(int n)
{
    int t[10],i=0,j,m,p;
    char a[][15]={"","One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine ","Ten ","eleven ","Twelve ","Thirteen ","Fourteen ","Fifteen ","Sixteen ","Seventeen ","Eighteen ","Nineteen "};
    char b[][15]={"","","Twenty ","Thirty ","Forty ","Fifty ","Sixty ","Seventy ","Eighty ","Ninety ","hundred "};
    char c[][10]={"","thousand ","million ","billion "};
    while(n>0)
    {
        t[i]=n%1000;
        n=n/1000;
        i++;
    }
    if(n==1000000000)
        printf("%s%s",a[1],c[3]);
    for(j=i-1;j>=0;j--)
    {
        if(t[j]>=100)
        {
            m=t[j]/100;
            t[j]=t[j]%100;
            printf("%s%sand",a[m],b[10]);
        }
        if(t[j]>=20)
        {
            m=t[j]/10;
            t[j]=t[j]%10;
            printf("%s",b[m]);
        }
        if(t[j]>0)
            printf("%s",a[t[j]]);
        if(j>0)
        {
            printf("%s",c[j]);
        }
    }
    printf("\n");
}
搜索更多相关主题的帖子: void 英语 Seventeen include 小数点 
2012-03-28 22:19
jj369258
Rank: 4
等 级:业余侠客
帖 子:116
专家分:226
注 册:2010-12-2
收藏
得分:10 
回复 楼主 qq393825817
第一次调用函数的时候,n没有值,再一个,
while(n>0)
     {
         t[i]=n%1000;
         n=n/1000;
         i++;
     }
这段控制循环条件有问题,因为你如果输入的大于0,则死循环!!
 
2012-03-29 13:28
明明白白
Rank: 2
等 级:论坛游民
帖 子:57
专家分:61
注 册:2012-3-19
收藏
得分:10 
float p;写在前面
#include<stdio.h>
void main()
{
    void trans(float n);
    float n;
    float p;
    scanf("%f",&n);
    p=(int)n;   //为啥这里不能把float转化为int类型的,该怎么改?我这个程序想把输入转化为英语。小数点后面程序不用!!就是求助这里为啥不能转化!!!//
    trans(p);
}
void trans(int n)
{
    int t[10],i=0,j,m,p;
    char a[][15]={"","One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine ","Ten ","eleven ","Twelve ","Thirteen ","Fourteen ","Fifteen ","Sixteen ","Seventeen ","Eighteen ","Nineteen "};
    char b[][15]={"","","Twenty ","Thirty ","Forty ","Fifty ","Sixty ","Seventy ","Eighty ","Ninety ","hundred "};
    char c[][10]={"","thousand ","million ","billion "};
    while(n>0)
    {
        t[i]=n%1000;
        n=n/1000;
        i++;
    }
    if(n==1000000000)
        printf("%s%s",a[1],c[3]);
    for(j=i-1;j>=0;j--)
    {
        if(t[j]>=100)
        {
            m=t[j]/100;
            t[j]=t[j]%100;
            printf("%s%sand",a[m],b[10]);
        }
        if(t[j]>=20)
        {
            m=t[j]/10;
            t[j]=t[j]%10;
            printf("%s",b[m]);
        }
        if(t[j]>0)
            printf("%s",a[t[j]]);
        if(j>0)
        {
            printf("%s",c[j]);
        }
    }
    printf("\n");
}
ok了!
2012-03-29 18:00
快速回复:哪位来看看出啥问题了。。。。
数据加载中...
 
   



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

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