团体程序设计天梯赛-练习集 L1-008 求整数段和 (10分)
程序员文章站
2024-02-27 12:28:15
...
#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;
}