zoukankan      html  css  js  c++  java
  • c语言 414 根据输入的整数,循环显示1234567890

    1、while语句

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

    2、for语句

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

    3、do语句

    #include <stdio.h>
    
    int main(void)
    {
        int i = 1, j;
        puts("please input an integer.");
        do
        {
            printf("j = "); scanf("%d", &j);
            if (j <= 0)
                puts("the range of j is: > 0");
        }
        while (j <= 0 );
        
        do
        {
            printf("%d", i % 10);
            i++;
        }
        while (i <= j);
        putchar('\n');
        
        return 0;
    }
  • 相关阅读:
    set集合 浅层拷贝会和深层拷贝
    "is"与"=="
    元组和字典
    运算符和列表
    Python 基础语法
    supervisor 安装配置详解
    如何运行vue项目
    过目不忘JS正则表达式
    vue Bus总线
    Robot Framework 环境安装(一)
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14678259.html
Copyright © 2011-2022 走看看