| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1966 人关注过本帖
标题:输出框有些问题,求教
只看楼主 加入收藏
专业课的小白
Rank: 1
等 级:新手上路
威 望:1
帖 子:56
专家分:0
注 册:2019-12-17
结帖率:40%
收藏
 问题点数:0 回复次数:6 
输出框有些问题,求教
#include<stdio.h>
void main()
{
    float s;
    int x;
    printf("此程序可以实现大小写的转换\n请输入阿拉伯数字:");
    scanf("%d\n",&s);
    x=s*100/10000000000;
    if(x==0)
    {
        x=s*100/1000000000;
        if(x==0)
        {
            x=s*100/100000000;
            if(x==0)
            {
                x=s*100/10000000;
                if(x==0)
                {
                    x=s*100/1000000;
                    if(x==0)
                    {
                        x=s*100/100000;
                        if(x==0)
                        {
                        x=s*100/10000;
                        if(x==0)
                        {
                            x=s*100/1000;
                            if(x==0)
                            {
                                x=s*100/100;
                                if(x==0)
                                {
                                    x=s*100/10;
                                    if(x==0)
                                    {
                                        x=s*100/1;
                                            if(x==0)
                                            {
                                                printf(" ");
                                            }
                                            else
                                            {
                                                if(x==1)
                                                    printf("壹分");
                                                if(x==2)
                                                    printf("贰分");
                                                if(x==3)
                                                    printf("叁分");
                                                if(x==4)
                                                    printf("肆分");
                                                if(x==5)
                                                    printf("伍分");
                                                if(x==6)
                                                    printf("陆分");
                                                if(x==7)
                                                    printf("柒分");
                                                if(x==8)
                                                    printf("捌分");
                                                if(x==9)
                                                    printf("玖分");
                                            }
                                    }
                                    else
                                    {
                                        if(x==1)
                                            printf("壹角");
                                        if(x==2)
                                            printf("贰角");
                                        if(x==3)
                                            printf("叁角");
                                        if(x==4)
                                            printf("肆角");
                                        if(x==5)
                                            printf("伍角");
                                        if(x==6)
                                            printf("陆角");
                                        if(x==7)
                                            printf("柒角");
                                        if(x==8)
                                            printf("捌角");
                                        if(x==9)
                                            printf("玖角");
                                    }
                                }
                                else
                                {
                                    if(x==1)
                                        printf("壹元");
                                    if(x==2)
                                        printf("贰元");
                                    if(x==3)
                                        printf("叁元");
                                    if(x==4)
                                        printf("肆元");
                                    if(x==5)
                                        printf("伍元");
                                    if(x==6)
                                        printf("陆元");
                                    if(x==7)
                                        printf("柒元");
                                    if(x==8)
                                        printf("捌元");
                                    if(x==9)
                                        printf("玖元");
                                }
                            }
                            if(x==1)
                                printf("壹佰");
                            if(x==2)
                                printf("贰佰");
                            if(x==3)
                                printf("叁佰");
                            if(x==4)
                                printf("肆佰");
                            if(x==5)
                                printf("伍佰");
                            if(x==6)
                                printf("陆佰");
                            if(x==7)
                                printf("柒佰");
                            if(x==8)
                                printf("捌佰");
                            if(x==9)
                                printf("玖佰");
                        }
                        else
                        {
                            if(x==1)
                                printf("壹佰");
                            if(x==2)
                                printf("贰佰");
                            if(x==3)
                                printf("叁佰");
                            if(x==4)
                                printf("肆佰");
                            if(x==5)
                                printf("伍佰");
                            if(x==6)
                                printf("陆佰");
                            if(x==7)
                                printf("柒佰");
                            if(x=8)
                                printf("捌佰");
                            if(x==9)
                                printf("玖佰");
                        }
                        }
                        else
                        {
                            if(x==1)
                                printf("壹仟");
                            if(x==2)
                                printf("贰仟");
                            if(x==3)
                                printf("叁仟");
                            if(x==4)
                                printf("肆仟");
                            if(x==5)
                                printf("伍仟");
                            if(x==6)
                                printf("陆仟");
                            if(x==7)
                                printf("柒仟");
                            if(x==8)
                                printf("捌仟");
                            if(x==9)
                                printf("玖仟");
                                 
                        }   
                    }
                    else
                    {
                        if(x==1)
                            printf("壹萬");
                        if(x==2)
                            printf("贰萬");
                        if(x==3)
                            printf("叁萬");
                        if(x==4)
                            printf("肆萬");
                        if(x=5)
                            printf("伍萬");
                        if(x==6)
                            printf("陆萬");
                        if(x==7)
                            printf("柒萬");
                        if(x==8)
                            printf("捌萬");
                        if(x==9)
                            printf("玖萬");
                        
                    }
                }
                else
                {
                    if(x==1)
                        printf("壹拾萬");
                    if(x==2)
                        printf("贰拾萬");
                    if(x==3)
                        printf("叁拾萬");
                    if(x==4)
                        printf("肆拾萬");
                    if(x==5)
                        printf("伍拾萬");
                    if(x==6)
                        printf("陆拾萬");
                    if(x==7)
                        printf("柒拾萬");
                    if(x==8)
                        printf("捌拾萬");
                    if(x==9)
                        printf("玖拾萬");
                    
                }
            }
            else
            {
                if(x==1)
                    printf("壹佰萬");
                if(x==2)
                    printf("贰佰萬");
                if(x==3)
                    printf("叁佰萬");
                if(x==4)
                    printf("肆佰萬");
                if(x==5)
                    printf("伍佰萬");
                if(x==6)
                    printf("陆佰萬");
                if(x==7)
                    printf("柒佰萬");
                if(x==8)
                    printf("捌佰萬");
                if(x==9)
                    printf("玖佰萬");
            }

        }
        else
        {
            if(x==1)
                printf("壹仟萬");
            if(x==2)
                printf("贰仟萬");
            if(x==3)
                printf("叁仟萬");
            if(x==4)
                printf("肆仟萬");
            if(x==5)
                printf("伍仟萬");
            if(x==6)
                printf("陆仟萬");
            if(x==7)
                printf("柒仟萬");
            if(x==8)
                printf("捌仟萬");
            if(x==9)
                printf("玖仟萬");
        }
    }
    else
    {
        if(x==1)
            printf("壹亿");
        if(x==2)
            printf("贰亿");
        if(x==3)
            printf("叁亿");
        if(x==4)
            printf("肆亿");
        if(x==5)
            printf("伍亿");
        if(x==6)
            printf("陆亿");
        if(x==7)
            printf("柒亿");
        if(x==8)
            printf("捌亿");
        if(x==9)
            printf("玖亿");
    }
}
搜索更多相关主题的帖子: 输入 输出 printf 转换 大小写 
2019-12-17 09:35
bcbbcclbbc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:194
专家分:528
注 册:2019-8-15
收藏
得分:0 
请说出你的问题点,什么输出框有问题?
你的输入是什么,输出实际是什么,想要达到什么效果?
2019-12-17 12:36
专业课的小白
Rank: 1
等 级:新手上路
威 望:1
帖 子:56
专家分:0
注 册:2019-12-17
收藏
得分:0 
回复 2楼 bcbbcclbbc
谢谢你回复我,我这个程序的目的是大小写的转换,就是从阿拉伯数字转到繁体的汉字,类似于银行收据之类的,我的问题是:当我输入阿拉伯数字的时候,我按回车它就不输出了,没有反应了。该怎么解决?
2019-12-17 14:10
bcbbcclbbc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:194
专家分:528
注 册:2019-8-15
收藏
得分:0 
回复 3楼 专业课的小白
首先程序运行,会报错
In function ‘main’:
7:11: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘float *’ [-Wformat=]
     scanf("%d\n",&s);
           ^

这个是说你让变量s读取一个int的数据,但是变量s定义的是float类型的数据。因此改成scanf("%f",&s);
其次就是你把if语句的功能想复杂了,它只会执行一遍,只要找到一个条件为真,则执行if后面一个语句,条件为假则执行else后面的语句。
你这个代码只能找到你输入的数的最大位 比如输入“12345”,输出为“壹万五万”,实际上是只能输出壹万,
五万是因为代码敲错了(可以这么理解)。
if(x=5)
                            printf("伍1萬");

你这代码写的过于冗杂了,如果了解过循环,这个是没多大问题的。而且清晰简洁。
2019-12-18 10:58
专业课的小白
Rank: 1
等 级:新手上路
威 望:1
帖 子:56
专家分:0
注 册:2019-12-17
收藏
得分:0 
回复 4楼 bcbbcclbbc
#include<stdio.h>
#include<math.h>
int main()
{
    double s,j;
    int i,q,g;
    char*a[]={"壹","贰","叁","肆","伍","陆","柒","捌","玖"};
    char*b[]={"元","拾","佰","仟","萬","拾","佰","仟","亿"};
    char*d[]={"角","分"};
    for( ; ; )
    {        
        printf("此程序用于实现大小写的转换\n您输入阿拉伯数字,我们将为您转换为汉字\n请输入阿拉伯数字:\n");
        scanf("%lf",&s);
        i=12;
        for(q=i-1;q>=0;q--)
        {
            j=s/pow(10,q);
            g=(int)j%10;
            if(g!=0)
                printf("%s%s",a[g-1],b[q]);
        }
        for(q=-1;q>=-2;q--)
        {
             j=s/pow(10,q);
            g=(int)j%10;
                if(g!=0)
                    printf("%s%s",a[g-1],d[-q-1]);
            }
        printf("\n\n");
    }
}
2019-12-19 11:03
专业课的小白
Rank: 1
等 级:新手上路
威 望:1
帖 子:56
专家分:0
注 册:2019-12-17
收藏
得分:0 
回复 4楼 bcbbcclbbc
那这样是不是简洁一些,但是我的输出有错误,如果我输到亿位,就会有错误
2019-12-19 11:05
bcbbcclbbc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:194
专家分:528
注 册:2019-8-15
收藏
得分:0 
抱歉,现在才回答。暂时先修改成这样,看看能否有效解决问题。
程序代码:
#include<stdio.h>
//#include<string.h>
#include<math.h>
int main()
{
    double s;
    char a[][4]={"","","","","","","","",""};
    char b[][4]={"","","","","","","","","亿"};
    char d[][4]={"",""};
    //printf("汉字所占字节为:%d\n",(int)strlen("汉"));    
    
    while(scanf("%lf",&s)==1)   
    {
        printf("此程序用于实现大小写的转换\n您输入阿拉伯数字,我们将为您转换为汉字\n请输入阿拉伯数字:\n");
        //printf("输入q退出");
        
        int x=s;
        int y=(s-(int)s+0.001)*100;    //这个小数部分转化可能有问题,你先看看你的运行结果。
        printf("\n您输入的数据中整数部分为: %d 小数部分为(保留两位有效数字):0.%d\n",x,y);
            
        int g;
       
        for(int i=8;i>=0;i--)   //整数部分转化。
        {
            g=x/pow(10,i);
            //printf("*%d ",g);
            if(g==0&&i==4) printf("%s",b[4]);
            if(g==0)  continue;
            x%=(int)pow(10,i);
            //printf("#%d \n",x);
            printf("%s%s",a[g-1],b[i]);
        }
        
        if(g=y/10) printf("%s%s",a[g-1],d[0]);  //小数部分转化。
        if(g=y%10) printf("%s%s",a[g-1],d[1]);
    }
    return 0;
}
2019-12-22 19:12
快速回复:输出框有些问题,求教
数据加载中...
 
   



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

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