5.9.1_P163《C++ Primer Plus (6th)》编程练习 答案

5.9.1_P163

本来想一起输入用空格隔开的两个数字,先用了这个简单的方案实现,以后学到了再优化。学习-ing。。。

 1 #include<iostream>
 2 int main(){
 3     using namespace std;
 4     cout<<"Enter a value:";
 5     int a;
 6     cin >> a;
 7     cout<<"Enter another bigger value:";
 8     int b;
 9     cin >> b;
10     int c;
11     int d;
12     if (a<=b){
13         c=a;
14         d=b;
15     }
16     else{
17         c=b;
18         d=a;
19     }
20     int sum_value=d;
21     for(int i=c;i<d;i++){
22         sum_value+=i;
23     }
24     cout<<"sum_value="<<sum_value;
25     cin.get();
26     cin.get();
27     return 0;
28 }

  

知识共享许可协议
本作品采用知识共享署名-非商业性使用-禁止演绎 3.0 中国大陆许可协议进行许可。

 

posted @ 2013-02-13 17:28  <无影人>  阅读(227)  评论(0编辑  收藏  举报