3.31

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

//创建一个数组,另每个元素的值,就是它们自己的下标
int main() {
    int arry[10];
    for (size_t x = 0;x != 10;++x) {
        arry[x] = x;
        cout << arry[x] << " " << x << endl;
    }
        return 0;
}

3.32

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

//创建一个数组,另每个元素的值,就是它们自己的下标
//将上一个数组拷贝给下一个数组
int main() {
    int arry[10];
    int arry2[10];
    for (size_t x = 0;x != 10;++x) {
        arry[x] = x;
        arry2[x] = arry[x];
        cout << arry[x] << " " << arry2[x] << endl;
    }
        return 0;
}

3.33

#include<string>
#include<iostream>
#include<vector>  //记得添加vector的头文件
using namespace std;

//用vcetor重做上一题
int main() {
    vector<int> arry;
    vector<int> arry2;
    for (int x = 0;x != 10;++x) {
        arry.push_back(x);
        arry2 = arry;
        cout << arry[x] << " " << arry2[x] << endl;
    }
        return 0;
}
最后修改:2022 年 12 月 05 日
如果觉得我的文章对你有用,请随意赞赏