首页 > 编程语言 > 详细

C++ Primer 第四版课后练习解答 习题1.17

时间:2017-03-12 22:57:44      阅读:190      评论:0      收藏:0      [点我收藏+]

注意:本随笔是直接参考《C++Primer(第四版)习题解答(完整版)》中的。此处主要是便于本人以后反复阅读。

习题1.编写程序,要求用户输入一组数。输出信息说明其中有多少个负数。

【解答】

 1 #include <iostream>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     int value,amount = 0;
 7     cout << "Enter values" << endl;
 8     cout << "输入文件结束符‘/0’可以终止输入" << endl;
 9 
10     while (cin>>value)
11     {
12         if (value<0)
13         {
14             ++amount;
15         }
16     }
17     cout <<"amount of all negative values read is "<< amount<<endl;
18     return 0;
19 }

 

Enter values
输入文件结束符‘/0’可以终止输入
1
3
4
5
5
0
-3
-5
/0
amount of all negative values read is 2
请按任意键继续. . .

 

C++ Primer 第四版课后练习解答 习题1.17

原文:http://www.cnblogs.com/haihai187/p/6539478.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!