• c语言42 输入两个整数的值,然后计算这两个数之间所有整数的和


    1、do语句;

    #include <stdio.h>
    
    int main(void)
    {
        int a, b, min, max, sum = 0;
        puts("please input two integers.");
        printf("a = "); scanf("%d", &a);
        printf("b = "); scanf("%d", &b);
        
        if (a > b)
        {
            min = b;
            max = a;
        }
        else
        {
            min = a;
            max = b;
        }
        
        do
        {
            sum += min;
            min++;
        }
        while (min <= max);
        
        printf("sum = %d\n", sum);
        return 0;
    }

    或者

    #include <stdio.h>
    
    int main(void)
    {
        int a, b, min, max, sum = 0;
        puts("please input two integers.");
        printf("a = "); scanf("%d", &a);
        printf("b = "); scanf("%d", &b);
        
        min = a > b ? b:a;
        max = a > b ? a:b;
        
        do
        {
            sum += min;
            min++;
        }
        while (min <= max);
        
        printf("sum = %d\n", sum);
        return 0;
    }

    2、while语句;

    #include <stdio.h>
    
    int main(void)
    {
        int a, b, min, max, sum = 0;
        puts("please input two integers.");
        printf("a = "); scanf("%d", &a);
        printf("b = "); scanf("%d", &b);
        
        min = a > b ? b:a;
        max = a > b ? a:b;
        
        while (min <= max)
        {
            sum += min;
            min++;
        }
        
        printf("sum = %d\n", sum);
        return 0;
    }

    3、for语句

    #include <stdio.h>
    
    int main(void)
    {
        int a, b, min, max, sum = 0;
        puts("please input two integers.");
        printf("a = "); scanf("%d", &a);
        printf("b = "); scanf("%d", &b);
        
        min = a > b ? b:a;
        max = a > b ? a:b;
        
        for (min; min <= max; min++)
        {
            sum += min;
        }
        
        printf("sum = %d\n", sum);
        return 0;
    }

    ————————————————————————————————————————————————————————————————————————————————————————————————————

    ————————————————————————————————————————————————————————————————————————————————————————————————————

    1、do语句

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

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, max, min, sum = 0;
        puts("please input two integers.");
        printf("i = "); scanf("%d", &i);
        printf("j = "); scanf("%d", &j);
        
        max = i > j ? i:j;
        min = i > j ? j:i;
        
        do
        {
            sum += min;
            min++;
        }
        while (min <= max);
        
        printf("sum = %d\n", sum);
        
        return 0;
    }

    2、while语句

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, max, min, sum = 0;
        puts("please input two integers.");
        printf("i = "); scanf("%d", &i);
        printf("j = "); scanf("%d", &j);
        
        if (i > j)
        {
            max = i;
            min = j;
        }
        else
        {
            max = j;
            min = i;
        }
        
        while (min <= max)
        {
            sum += min;
            min++;
        }
        printf("sum = %d\n", sum);
        
        return 0;
    }

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, max, min, sum = 0;
        puts("please input two integers.");
        printf("i = "); scanf("%d", &i);
        printf("j = "); scanf("%d", &j);
        
        max = i > j ? i:j;
        min = i > j ? j:i;
        
        while (min <= max)
        {
            sum += min;
            min++;
        }
        printf("sum = %d\n", sum);
        
        return 0;
    }

    3、for语句

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, max, min, sum = 0;
        puts("please input two integers.");
        printf("i = "); scanf("%d", &i);
        printf("j = "); scanf("%d", &j);
        
        if (i > j)
        {
            max = i;
            min = j;
        }
        else
        {
            max = j;
            min = i;
        }
        
        for (min; min <= max; min++)
        {
            sum += min;
        }
        printf("sum = %d\n", sum);
        
        return 0;
    }

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, max, min, sum = 0;
        puts("please input two integers.");
        printf("i = "); scanf("%d", &i);
        printf("j = "); scanf("%d", &j);
        
        max = i > j ? i:j;
        min = i > j ? j:i;
        
        for (min; min <= max; min++)
        {
            sum += min;
        }
        printf("sum = %d\n", sum);
        
        return 0;
    }
  • 相关阅读:
    事件处理之二:点击事件监听器的五种写法 分类: H1_ANDROID 2013-09-11 10:32 4262人阅读 评论(1) 收藏
    如何解决安卓SDK无法下载Package的问题 分类: H1_ANDROID 2013-09-09 10:26 1199人阅读 评论(0) 收藏
    adb常用命令 分类: H1_ANDROID 2013-09-08 15:22 510人阅读 评论(0) 收藏
    用IBM WebSphere DataStage进行数据整合: 第 1 部分 分类: H2_ORACLE 2013-08-23 11:20 688人阅读 评论(0) 收藏
    三大主流ETL工具选型 分类: H2_ORACLE 2013-08-23 11:17 426人阅读 评论(0) 收藏
    ETL概述 分类: H2_ORACLE 2013-08-23 10:36 344人阅读 评论(0) 收藏
    POI操作Excel常用方法总结 分类: B1_JAVA 2013-08-23 10:01 349人阅读 评论(0) 收藏
    段的创建表user_segments 分类: H2_ORACLE 2013-08-10 11:13 714人阅读 评论(0) 收藏
    让android项目支持boost 支持c++11
    unity中全屏背景图缩放
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14674664.html
Copyright © 2020-2023  润新知