0

I want to combine two array into one array. but the second array I want to combine with first array copy the value of first array. how to make the second array not copy the value of first array while combine the array into one array?

#include<iostream>

using namespace std;

int main()
{
    int arr1[9], arr2[9], arr3[18];
    // get the value of arr1
    for(int i = 0; i < 9; i++) {
        arr1[i] = rand()%100;
    }

    // get the value of arr2
    for(int i = 0; i < 9; i++) {
        arr2[i] = rand()%100;
    }

    // output the arr1
    cout << "arr1 = ";
    for(int i = 0; i < 9; i++) {
        cout << arr1[i] << " ";
    }
    cout << "\n";

    // output the arr2
    cout << "arr2 = ";
    for(int i = 0; i < 9; i++) {
        cout << arr2[i] << " ";
    }
    cout << "\n";

    // combining the arr1 and arr2 into arr3
    for(int i = 0; i < 9; i++) {
        arr3[i] = arr1[i];
    }
    for(int i = 9; i < 18; i++) {
        arr3[i] = arr2[i];
    }

    // output the arr3
    cout << "arr3 = ";
    for(int i = 0; i < 18; i++) {
        cout << arr3[i] << " ";
    }
    cout << "\n";
    
    return 0;
}

0 Answers0