| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 794 人关注过本帖
标题:求一个不多于5位正整数是几位数,下面是我弄的......总是输出4
只看楼主 加入收藏
Dramalife
Rank: 2
来 自:河北唐山
等 级:论坛游民
帖 子:35
专家分:50
注 册:2013-9-26
结帖率:83.33%
收藏
已结贴  问题点数:20 回复次数:12 
求一个不多于5位正整数是几位数,下面是我弄的......总是输出4
程序代码:
[code]#include<stdio.h>
main()
{
int num;
printf("please input a number less than 99999 and more than 0\n");
scanf("%d",num);
if (num<=9)printf("1 place");
else if (num>=10,num<=99)printf("2 place");
else if (num<=999)printf("3 place");
else if (num<=9999)printf("4 place");
else if (num<=99999)printf("5 please");
return 0;

}
[/code]

还有一个

程序代码:
#include<stdio.h>
main()
{
int num,place;
printf("please input a number less than 99999 and more than 0\n");
scanf("%d",num);
if (num<=9)place=1;
else if (num>=10,num<=99)place=2;
else if (num>=100,num<=999)place=3;
else if (num>=1000,num<=9999)place=4;
else if (num>=10000,num<=99999)place=5;
printf("place=%d",place);
return 0;

}

不知道为什么,输出结果总是不变
搜索更多相关主题的帖子: include 正整数 
2013-10-17 20:06
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:6 
程序代码:
int main()
{
    int num;
    printf("please input a number less than 99999 and more than 0:\n");
    scanf("%d",&num);
    int oldnum=num;
    int digit=0;
    while(num>0)
    {
        num=num/10;
        digit++;
    }
    printf("%d的位数是%d.\n",oldnum,digit);
    return 0;

} 
tooooooooooooooooooooooooooooooooooooooo


DO IT YOURSELF !
2013-10-17 20:24
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
如果一定要用if嵌套

大约如此
程序代码:
int num;
    printf("please input a number less than 99999 and more than 0\n");
    scanf("%d",&num);
    if (num<=9)printf("1 place");
    else if (num>=10 && num<=99) printf("2 place");
    else if (num>=100 && num<=999) printf("3 place");
    else if (num>=1000 && num<=9999) printf("4 place");
    else if (num>=10000 && num<=99999) printf("5 please");
    return 0;



DO IT YOURSELF !
2013-10-17 20:31
xp0213
Rank: 7Rank: 7Rank: 7
来 自:湖北武汉
等 级:黑侠
威 望:1
帖 子:222
专家分:524
注 册:2011-10-26
收藏
得分:6 
#include<stdio.h>
main()
{
int num;
printf("please input a number less than 99999 and more than 0\n");
scanf("%d",&num);
if (num<=9)printf("1 place");
else if (num<=99)printf("2 place");
else if (num<=999)printf("3 place");
else if (num<=9999)printf("4 place");
else if(num<=99999)printf("5 place");
else printf("input wrong");
return 0;

}
第一段代码改正。注意输入的取地址符号;;
2013-10-17 20:31
tlliqi
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:204
帖 子:15453
专家分:65956
注 册:2006-4-27
收藏
得分:0 
程序代码:
#include<stdio.h>

int main()
{
    int num = 0;
   
    printf("please input a number less than 99999 and more than 0\n");
   
    scanf("%d", num);
        {
        if (num > 0, num <= 9)
            printf("1 place");
            else if (num >= 10, num <= 99)
            printf("2 place");
            else if (num >= 100, num <= 999)
            printf("3 place");
            else if (num >= 1000, num <= 9999)
            printf("4 place");
            else if (num >= 10000, num <= 99999)
            printf("5 please");

        }
return 0;
}
2013-10-17 20:39
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
以下是引用tlliqi在2013-10-17 20:39:56的发言:

#include
 
int main()
{
    int num = 0;
   
    printf("please input a number less than 99999 and more than 0\n");
   
    scanf("%d", num);
        {
        if (num > 0, num <= 9)
            printf("1 place");
            else if (num >= 10, num <= 99)
            printf("2 place");
            else if (num >= 100, num <= 999)
            printf("3 place");
            else if (num >= 1000, num <= 9999)
            printf("4 place");
            else if (num >= 10000, num <= 99999)
            printf("5 please");
 
        }
return 0;
}
嘻嘻  scanf后没有寻址

DO IT YOURSELF !
2013-10-17 20:42
tlliqi
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:204
帖 子:15453
专家分:65956
注 册:2006-4-27
收藏
得分:0 
回复 6楼 wp231957
改 嘿嘿
程序代码:
#include<stdio.h>

int main()
{
    int num = 0;
   
    printf("please input a number less than 99999 and more than 0\n");
   
    scanf("%d", &num);
        {
        if (num > 0, num <= 9)
            printf("1 place\n");
            else if (num >= 10, num <= 99)
            printf("2 place\n");
            else if (num >= 100, num <= 999)
            printf("3 place\n");
            else if (num >= 1000, num <= 9999)
            printf("4 place\n");
            else if (num >= 10000, num <= 99999)
            printf("5 please\n");

        }
return 0;
}


2013-10-17 21:04
天楚
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:楚地
等 级:小飞侠
帖 子:550
专家分:2113
注 册:2013-3-14
收藏
得分:6 
这个要取地址scanf("%d",&num);

没有哪条路好走,选择了,就坚持下去~~~~
2013-10-17 21:05
qunxingw
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:24
帖 子:1676
专家分:7295
注 册:2011-6-30
收藏
得分:1 
4楼条件语句用得舒服

www.qunxingw.wang
2013-10-17 21:20
小小程序猿
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:1
帖 子:755
专家分:2785
注 册:2013-7-18
收藏
得分:1 
2楼的循环,4楼的条件,学习了

孤独与寂寞是催化一个人迅速成长的良药,没有之一
2013-10-17 21:47
快速回复:求一个不多于5位正整数是几位数,下面是我弄的......总是输出4
数据加载中...
 
   



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

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