while语句

#include<iostream>
using namespace std;

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

  

 

#include<iostream>
using namespace std;

int main()
{
	int sum = 0,value;
	cout <<"Enter several numbers then enter end!"<<endl;
	while(cin>> value)
	{
		sum += value;
	}
	cout <<"sum is: "<< sum <<endl;

	return 0;
}

  

posted @ 2013-08-28 11:02  haihai187  阅读(125)  评论(0)    收藏  举报