分别使用for、while、do语句.从键盘输入一个1-20的整数,并计算s=1+2+3+...n的值。我在while卡住了求教
#include <iostream>using namespace std;
int main()
{
int i=1,s=0;
int n;
cin>>n;
while(i<=20,s=s+i){
s=i+n;
i++;
}
cout<<"1+2+3+...+n的值为"<<s<<endl;
return 0;
}
2018-11-07 12:54
2018-11-07 12:54

2018-11-07 13:10

2018-11-07 13:15