zoukankan      html  css  js  c++  java
  • c语言416 输入一个整数值,显示该整数值以下的所有奇数

    1、while语句

    #include <stdio.h>
    
    int main(void)
    {
        int i;
        puts("please input an integer.");
        do
        {
            printf("i = "); scanf("%d", &i);
            if (i <= 0)
                puts("the range of i is : > 0 ");
        }
        while (i <= 0);
        
        while (i > 0)
        {
            if (i % 2)
                printf("%d ", i);
            i--;
        }
        
        return 0;
    }

    2、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);
            i += 2;
        }
        
        return 0;
    }

    3、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)
        {
            if (i % 2)
                printf("%d ", i);
            i++;
        }
        
        return 0;
    }

    4、for语句

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

    5、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+=2)
        {
            printf("%d ", i);
        }
        putchar('\n');
        
        return 0;
    }

    6、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++)
        {
            if (i % 2)
                printf("%d ", i);
        }
        putchar('\n');
        
        return 0;
    }

    7、do语句

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

    8、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);
            i += 2;
        }
        while (i <= j);
        putchar('\n');
        
        return 0;
    }

    9、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
        {
            if (i % 2)
                printf("%d ", i);
            i++;
        }
        while (i <= j);
        putchar('\n');
        
        return 0;
    }
  • 相关阅读:
    政务公开系统专栏首页的跨站攻击漏洞
    Spring+XFire WSSecurity安全认证开发感悟
    Appfuse使用中遇到的问题及解决方案
    How to get the rowid when insert the data to Oracle database
    How to configure CVS in IntelliJ IDEA
    localhost打不开 127.0.0.1可以打开,,,或 hosts 文件不起作用的解决方法
    ASp.net中Froms验证方式
    ASP.NET 页面执行顺序详解
    【转】防止用户通过后退按钮重复提交表单ASP中的response.Buffer,Response.Expires,Response.CacheControl
    页面事件(Init,Load,PreRender)执行顺序__简单总结
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14679227.html
Copyright © 2011-2022 走看看