c语言中计算两个整数之间的所有整数的和

 

1、

#include <stdio.h>

int main(void)
{
    int a,b;
    puts("please input two integers.");
    printf("a = "), scanf("%d", &a);
    printf("b = "), scanf("%d", &b);
    int sum = 0;
    do
    {
    
        sum = sum + b;
        b = b + 1;
        
    }
    while (b <= a );
    printf("sum = %d.\n", sum);
    return 0;
}

 

posted @ 2021-01-04 14:56  小鲨鱼2018  阅读(2303)  评论(0编辑  收藏  举报