团体程序设计天梯赛-练习集 L1-008 求整数段和 (10分)

在这里插入图片描述

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    int temp = a, sum = 0;
    while (temp <= b)
    {
        for (int j = 0; j < 5 && temp <= b; j++)
        {
            printf("%5d", temp);
            sum += temp;
            temp++;
        }
        cout << endl;
    }
    cout << "Sum = " << sum;
    return 0;
}
发布了75 篇原创文章 · 获赞 58 · 访问量 3280

猜你喜欢

转载自blog.csdn.net/qq_44458489/article/details/105001057