7302人加入学习
(18人评价)
C++编程系列 第一季编程基础

制作于2018年2月7日

价格 免费

练习题

1,下面的代码会打印什么内容

    int i;

    for(int i = 0; i < 5; i++)

        cout << i;

        cout << endl;

结果:01234

 

2,下面的代码会打印什么内容

    int j;

    for(j = 0; j < 11; j+=3)

        cout << j;

    cout << endl << j << endl;

结果:

0369

12

 

3,下面的代码会打印什么内容

    int j = 5;

    while(++j<9)

        cout << j++ << endl;

结果:

4,下面的代码会打印什么内容

    int k = 8;

    do

        cout << "k = " << k << endl;

    while(k++ < 5);

5,编写一个打印 1 2 4 8 16 32 64 的for循环

6,编写一个程序,让用户输入两个整数,输出这两个整数之间(包括这两个整数)所有整数的和。

    比如 2 5    里面整数有 2 4 = 6

7,编写一个程序,让用户可以持续输入数字,每次输入数字,报告当前所有输入的和。当用户输入0的时候,程序结束。

 

 

 

 

#include <iostream>
using namespace std;

int main()
{
    //for (int i = 0; i < 5; i++)
    //    cout << i;
    //cout << endl;// 结果:01234

    int i = 9;
    //++i;
    //--i;
    //cout << i << endl;
    //int result = (i++) + 1; // 结果:10 10
    //int result = ++i + 1; // 结果:11 10
    //cout << result << " " << i << endl;
    
    //{
    //    cout << i++ << endl; // 9
    //    cout << i << endl; // 10
    //}

    //{
    //    cout << ++i << endl; // 10
    //    cout << i << endl; // 10
    //}
    
    //{
    //    cout << i-- << endl; // 9
    //    cout << i << endl; // 8
    //}
    {
        cout << --i << endl; // 8
        cout << i << endl; // 8
    }
    return 0;
}

[展开全文]