View difference between Paste ID: M3MRBEhm and nzGe8sTW
SHOW: | | - or go back to the newest paste.
1
#include<iostream>
2
using namespace std;
3
int main(){
4
  int arr1[2][5]={{1,2,3,4,5}, {10,9,8,7,6}};
5
  int arr2[5][2]={0};
6
  int arr3[5][2]={0};
7
  int countOdd, countEven;
8
  //print the first array
9
  cout << "arr1" << endl;
10
  for(int i=0; i<2; i++){
11
    for(int j=0; j<5; j++){
12
      cout << arr1[i][j] << " ";
13
        }
14
        cout << endl;
15
  }
16
  cout << endl;
17
  cout << "arr2" << endl;
18-
	  cout << arr2[i][j] << " ";
18+
19
  for(int i=0; i<5; i++){
20
    for(int j=0; j<2; j++){
21
          cout << arr2[i][j] << " ";
22
        }
23
        cout << endl;
24
  }
25
 
26
  cout <<  "\nAfter transfer... \n" << endl;
27
 
28
  //transfer the entry in array 1 to array 2.
29
  for(int i=0; i<5; i++){
30
    arr2[i][0] = arr1[1][i];
31
    arr2[i][1] = arr1[0][i];
32
  }
33
  
34
  cout << "arr1" << endl;
35-
	  cout << arr1[i][j] << " ";
35+
36
  for(int i=0; i<2; i++){
37
    for(int j=0; j<5; j++){
38
          cout << arr1[i][j] << " ";
39
        }
40
        cout << endl;
41
  }
42
  cout << endl;
43-
	  cout << arr2[i][j] << " ";
43+
  cout << "arr2" << endl;
44
  //print the second array
45
  for(int i=0; i<5; i++){
46
    for(int j=0; j<2; j++){
47
          cout << arr2[i][j] << " ";
48
        }
49
        cout << endl;
50
  }
51
  
52
  cout << "\nGet arr3 from arr2\n\n";
53
  //do the transfer for arr3
54
  
55
  for(int i=0; i<5; i++){
56
    if(i%2 == 0){
57
      arr3[countOdd][0] = arr2[i][1];
58
	  ++countOdd;
59
	}
60
	else{
61
	  arr3[countEven][1] = arr2[i][1];
62
	  ++countEven;
63
	}
64
  }
65
  for(int i=4; i>= 0; i--){
66
    if(i%2 == 0){
67
	  arr3[countEven][1] = arr2[i][0];
68
	  ++countEven;
69
	}
70
	else{
71
	  arr3[countOdd][0] = arr2[i][0];
72
	  ++countOdd;
73
	}
74
  }
75
  for(int i=0; i<5; i++){
76
    for(int j=0; j<2; j++){
77
	  cout << arr3[i][j] << " ";
78
	}
79
	cout << endl;
80
  }
81
  return 0;
82
}