zoukankan      html  css  js  c++  java
  • c语言46 输出小于输入值的所有正偶数

    输出小于输入值的所有正偶数。

    1、while语句

    #include <stdio.h>
    
    int main(void)
    {
        int i = 2, j;
        puts("please input an integer.");
        printf("j = "); scanf("%d", &j);
        
        while ( i <= j)
        {
            printf("%d ", i);
            i += 2;
        }
        putchar('\n');
        return 0;
    }

    2、while语句

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

    3、while语句

    #include <stdio.h>
    
    int main(void)
    {
        int i;
        puts("please input an integer.");
        printf("i = "); scanf("%d", &i);
        
        while (i > 0)
        {
            if (i % 2 == 0)
                printf("%d ", i);
            i--;
        }
        putchar('\n');
        return 0;
    }

    4、for语句

    #include <stdio.h>
    
    int main(void)
    {
        int i, j;
        puts("please input an integer.");
        printf("j = "); scanf("%d", &j);
        
        for (i = 2; i <= j; i+=2)
        {
            printf("%d ", i);
        }
        putchar('\n');
        return 0;
    }

    5、for语句

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

    6、for语句

    #include <stdio.h>
    
    int main(void)
    {
        int i;
        puts("please input an integer.");
        printf("i = "); scanf("%d", &i);
        
        for (i; i > 0; i--)
        {
            if (i % 2 == 0)
                printf("%d ", i);
        }
        putchar('\n');
        return 0;
    }

    7、do语句

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

    8、do语句

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

    9、do语句

    #include <stdio.h>
    
    int main(void)
    {
        int i;
        puts("please input an integer.");
        printf("i = "); scanf("%d", &i);
        
        do
        {
            if (i % 2 == 0)
                printf("%d ", i);
            i--;
        }
        while (i > 0);
        putchar('\n');
        
        return 0;
    }
  • 相关阅读:
    epoll 使用详解
    STL 较详尽总结
    可视化对比排序算法
    统治世界的十大算法
    Vector Demo
    Git远程操作(附重要原理图)
    Wireshark(五):TCP窗口与拥塞处理
    Wireshark(四):网络性能排查之TCP重传与重复ACK
    Wireshark(三):应用Wireshark IO图形工具分析数据流
    Wireshark(二):应用Wireshark观察基本网络协议
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14675088.html
Copyright © 2011-2022 走看看