小葫芦藤的博客

欢迎交流

统计

最新评论

输入未知个数的求和(c++)

#include<iostream>
int main()
{
 int sum=0,value;
 while(cin>>value)
  sum+=value;
 cout<<"sum is:"<<sum<<endl;

 return 0;

}
在运行的时候,连续输入N个数,用空格分开,在windows中,按ctrl+z结束,然后回车运行,在unix中,用ctrl+d结束,回车运行即可。

posted on 2008-08-12 12:23 李晓飞 阅读(1165) 评论(1)  编辑 收藏 引用

评论

# re: 输入未知个数的求和(c++) 2008-08-13 00:36 踏雪赤兔

welcome to the world of C++!
better not include <iostream.h>, try <iostream> instead.  回复  更多评论   

只有注册用户登录后才能发表评论。