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

制作于2018年2月7日

价格 免费

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

    int j = 5;

    while(++j<9)

        cout << j++ << endl;

结果:

6

8

  

 int j = 5;
    while (++j < 9) // j=j+1 ; j<9
        cout << j++ << endl; // cout<<j<<endl; j=j+1;
    // 6
    // 8

 

 

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

    int k = 8;

    do

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

    while(k++ < 5);

结果:

 k = 8

 

 

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

siki:

for(int i = 1; i <= 64; i*=2)

{

    cout<<i<<endl;

}

    //j=1;    res=1;
    //j=1*2;  res=2;
    //j=2*2;  res=4
    //j=4*2;  res=8;
    //j=8*2;  res=16;
    //j=16*2; res=32;
    //j=32*2; res=64

 

 

自写:

#include <iostream>
#include <cmath>
using namespace std;

int main()

{

    for (int a = 0; a < 7; a++)
    {
        cout << pow(2, a) << " ";
    }
    //a=0,res=1
    //a=1,res=2
    //a=2,res=4
    //a=3,res=8
    //a=4,res=16
    //a=5,res=32
    //a=6,res=64

    return 0;

}

 

 

 

 

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

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

 

 

    cout << "请输入第一个数字:";
    int num1;
    cin >> num1;
    cout << "请输入第二个数字:";
    int num2;
    cin >> num2;

    int total = 0;

    for (int i = num1; i <= num2; i++)
    {
        total += i;
    }
    cout << total << endl; // 14
    // 2 - 5    2 3 4 5

[展开全文]

授课教师

SiKi学院老师

课程特色

下载资料(1)
视频(58)