1.9
#include <iostream>
using namespace std;
int main()
{
int res=0;
int i = 50;
while (i <= 100)
{
res += i;
++i;
}
cout << res <<endl;
}
1.10
int main()
{
int i=10;
while (i >=0)
{
cout << i <<endl;
--i;
}
}
1.11
#include <iostream>
using namespace std;
int main()
{
int min, max,tmp;
cout << "please input two number" << endl;
cin >> min >> max;
if (min >= max)
{
tmp = min;
min = max;
max = tmp;
}
/*不使用额外空间交换两个数的算法:
max = min + max;
min = max - min;
max = max - min;
*/
while (min <= max)
{
cout << min <<endl;
++min;
}
}
1.16
#include <iostream>
using namespace std;
int main()
{
int tmp=0,sum=0;
while (cin>>tmp)
{
sum += tmp;//按下任意不是数字的字符退出循环如q
}
cout << sum << endl;
}