C++ while语句

下面是C++ primer中使用while语句编写从1到10的求和程序:


#include 

int main()
{
	int sum = 0, val = 1;
	while (val <= 10) {
		sum += val;
		++val;	
	}
	std::cout << "Sum of 1 to 10 inclusive is " << sum << std::endl;
	getchar();
	return 0;
}


你可能感兴趣的:(C++Primer)