急求一道简单C++编程题。

急求一道简单C++编程题。题目看图

#include<iostream>
using namespace std;
int main()
{
int i,j,s1=0,s2=0;
int i1,j1;
int sign=-1;
cout << "请输入起始值bg:";
cin >> i;
cout << "请输入终止值end:";
cin >> j;
i1=i;j1=i+1;
while (i1 <= j)
{
s1+=i1;
i1=i1+2;
}
while(j1<= j)
{
s2+=j1;
j1=j1+2;
}
cout << "sum=";
for(i1=i;i1<j;++i1)
{
cout << i1;
if(sign == -1)
cout << '-';
else
cout << '+';
sign*=-1;
}
cout << j << '=' << s1-s2 << endl;
return 0;
}追问

谢谢

温馨提示:答案为网友推荐,仅供参考
相似回答