我想从这个程序中给我一个+(a+1)+(a+2)的答案+b
I want from this program to give me the answer of a+(a+1)+(a+2)...+b
我想从这个程序中给我一个+(a+1(+(a+2(的答案+b但是给我a+b!救命!
#include <iostream>
using namespace std;
int main(){
int a, b, c;
cout << "Enter the value of the first number" << endl;
cin >> a; cout << endl;
cout << "Enter the value of the second number" << endl;
cin >> b; cout << endl;
for(a; c <= b; c++){
c = c + 1;
}
cout << "The sum of the numbers between " << a << " and " << b << " is " << c << endl;
return 0;
}
您想要的代码在这里:
#include <iostream>
using namespace std;
int main(){
int a, b, c=0;
cout << "Enter the value of the first number" << endl;
cin >> a; cout << endl;
cout << "Enter the value of the second number" << endl;
cin >> b; cout << endl;
for(int i=a;i<=b;i++) c+=i;//notice here !!!
cout << "The sum of the numbers between " << a << " and " << b << " is " << c << endl;
return 0;
}
相关文章:
- 没有找到相关文章