A C++ program to copy the content of an array into another array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

A C++ program to copy the content of an array into another array

2nd May 2017, 11:01 PM
olamilekan
olamilekan - avatar
6 Answers
+ 10
welcome.. one note for header file just put #include<iostream> instead of #include<iostream.h>
2nd May 2017, 11:58 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 9
let for an integer array of size 5: #include<iostream.h> using namespace std; int main(){ // declare first array int arr1[5]; /* declare another array of greater than or equal size and same type */ int arr2[5]; // insert the value of the first array for(int i =0; i < 5; i++){ cout <<"insert the value of arr1["<<i+1<<"] ="; cin >> arr1[i]; } /* asign the values of the 1st array to the second one. */ for(int i =0; i < 5; i++){ arr2[i] = arr1[i]; } return 0; }
2nd May 2017, 11:27 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 9
because we did not try to output it. add this loop to the end of the programm to get the values of arr2 cout << "\n\nThe values of arr2 are:" << endl; for(int i =0; i<5; i++){ cout << "arr2[" << i+1 << "] = " << arr2[i]<< endl; }
3rd May 2017, 1:49 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 1
Thanks..... I would run it in the morning
2nd May 2017, 11:43 PM
olamilekan
olamilekan - avatar
0
Please help me out
2nd May 2017, 11:01 PM
olamilekan
olamilekan - avatar
0
But the output is not specified..... Did you try running it
3rd May 2017, 11:58 AM
olamilekan
olamilekan - avatar