题目描述
求区间的和
C++ 代码
#include <bits/stdc++.h>
using namespace std;
int sum(int l, int r)
{
int res = 0;
cin>> l >> r;
for(int i = l; i <= r; i++){
res += i;
}
return res;
}
int main()
{
int l, r, res = 0;
cin>> l >> r;
cout<< sum(l, r) << endl;
return 0;
}