zoukankan      html  css  js  c++  java
  • c语言412 输入一个整数值显示其位数

    1、while语句

    #include <stdio.h>
    
    int main(void)
    {
        int i, cnt = 0;
        puts("please input an integer.");
        do
        {
            printf("i = "); scanf("%d", &i);
            if (i <= 0)
                puts("the range of i is : > 0");
        }
        while (i <= 0);
        
        printf("the span number of %d is: ", i);
        while (i > 0)
        {
            i /= 10;
            cnt++;
        }
        printf("%d\n", cnt);
        
        return 0;
    }

    2、for语句

    #include <stdio.h>
    
    int main(void)
    {
        int i, cnt = 0;
        puts("please input an integer.");
        do
        {
            printf("i = "); scanf("%d", &i);
            if (i <= 0)
                puts("the range of i is: > 0");
        }
        while (i <= 0);
        
        printf("the span number of %d is: ", i);
        for (i; i > 0; i /= 10)
        {
            cnt++;
        }
        printf("%d\n", cnt);
        
        return 0;
    }

    3、do语句

    #include <stdio.h>
    
    int main(void)
    {
        int i, cnt = 0;
        puts("please input an integer.");
        do
        {
            printf("i = "); scanf("%d", &i);
            if (i <= 0)
                puts("the range of i is : > 0");
        }
        while (i <= 0);
        
        printf("the span number of %d is: ", i);
        do
        {
            cnt++;
            i /= 10;
        }
        while (i > 0);
        printf("%d\n", cnt);
        
        return 0;
    }
  • 相关阅读:
    启动django报错
    celery简单使用
    git简单使用
    selinux干扰mysql启动
    python操作xml文件时,带有^M符号
    获取服务器内网地址
    WebStorm激活
    linux nohup python 后台运行无输出问题
    安装FTP
    sql server还原数据库代码
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14677868.html
Copyright © 2011-2022 走看看