Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main(){
- int arr1[2][5]={{1,2,3,4,5}, {10,9,8,7,6}};
- int arr2[5][2]={0};
- int arr3[5][2]={0};
- int countOdd, countEven;
- //print the first array
- cout << "arr1" << endl;
- for(int i=0; i<2; i++){
- for(int j=0; j<5; j++){
- cout << arr1[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- cout << "arr2" << endl;
- //print the second array
- for(int i=0; i<5; i++){
- for(int j=0; j<2; j++){
- cout << arr2[i][j] << " ";
- }
- cout << endl;
- }
- cout << "\nAfter transfer... \n" << endl;
- //transfer the entry in array 1 to array 2.
- for(int i=0; i<5; i++){
- arr2[i][0] = arr1[1][i];
- arr2[i][1] = arr1[0][i];
- }
- cout << "arr1" << endl;
- //print the first array
- for(int i=0; i<2; i++){
- for(int j=0; j<5; j++){
- cout << arr1[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- cout << "arr2" << endl;
- //print the second array
- for(int i=0; i<5; i++){
- for(int j=0; j<2; j++){
- cout << arr2[i][j] << " ";
- }
- cout << endl;
- }
- cout << "\nGet arr3 from arr2\n\n";
- //do the transfer for arr3
- for(int i=0; i<5; i++){
- if(i%2 == 0){
- arr3[countOdd][0] = arr2[i][1];
- ++countOdd;
- }
- else{
- arr3[countEven][1] = arr2[i][1];
- ++countEven;
- }
- }
- for(int i=4; i>= 0; i--){
- if(i%2 == 0){
- arr3[countEven][1] = arr2[i][0];
- ++countEven;
- }
- else{
- arr3[countOdd][0] = arr2[i][0];
- ++countOdd;
- }
- }
- for(int i=0; i<5; i++){
- for(int j=0; j<2; j++){
- cout << arr3[i][j] << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment