跳至正文
-
Subscribe to our newsletter & never miss our best posts. Subscribe Now!
小奥的学习笔记

万丈高楼平地起,勿在浮沙筑高台

小奥的学习笔记

万丈高楼平地起,勿在浮沙筑高台

  • 首页
  • Sample Page
  • 隐私策略
  • GuestBook
  • 慕课课程(MOOC’s Lessons)
  • Footprints
  • About Me
  • 个人履历
  • 首页
  • Sample Page
  • 隐私策略
  • GuestBook
  • 慕课课程(MOOC’s Lessons)
  • Footprints
  • About Me
  • 个人履历
关

搜索

  • https://www.facebook.com/
  • https://twitter.com/
  • https://t.me/
  • https://www.instagram.com/
  • https://youtube.com/
Subscribe

第五章编程题因为时间原因我就只做了前两个题,从第6章开始全部都做。

5.1输入2个整数,输出这2个之间(包括这两个)所有整数和

代码如下:

#include<iostream>

#include<cstring>

using namespace std;

int main() {

       int a, b;

       int sum = 0;

       cout << "Enter two number:" << endl;

       cin >> a >> b;

       if (a < b)

       {

              for (int i = a; i <= b; i++)

                     sum += i;

       }

       else if (a > b)

       {

              for (int i = b; i <= a; i++)

                     sum += i;

       }

       cout << sum << endl;

       system("pause");

       return 0;

}

 

5.2 编写一个整数输入程序,每输入一个数,显示累计和,输入0停止

#include<iostream>

#include<cstring>

using namespace std;

int main() {

       int i;

       int count=0;

       cout << "Enter number:" << endl;

       cin >> i;

       while (i != 0)

       {

              count += i;

              cout <<"到目前的和为" << count << endl;

              cin >> i;

       }

       system("pause");

       return 0;

}

 

作者

yszhang

关注我
其他文章
上一个

计算机组成原理笔记第五章(5.6)

下一个

计算机组成原理笔记第六章(6.1~6.2)

一条评论
  1. 个人学习笔记整理 - 小奥の部落格说道:
    2019年10月18日 14:48

    […] C++ Primer Plus(第五版)第5章编程题答案 […]

    回复

发表回复 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注

Copyright 2026 — 小奥的学习笔记. All rights reserved. Blogsy WordPress Theme