betweensum.cpp

来自「C++ primer plus第五章编程练习的代码」· C++ 代码 · 共 28 行

CPP
28
字号
#include <iostream>

int main()
{
	using namespace std;
	int lower;
	int upper;
	cout<<"Please input the lower:";
	cin>>lower;
	cout<<"Please input the upper:";
	cin>>upper;
	while(lower>upper)
	{
		cout<<"lower have to less than upper!please input again…"<<endl;
		cout<<"Please input the lower:";
		cin>>lower;
		cout<<"Please input the upper:";
		cin>>upper;
	}
	int sum=0;
	for(;lower<=upper;lower++)
	{	
		sum+=lower;
	}
	cout<<"result is:"<<sum<<endl;
	system("Pause");
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?