convert 1-d array into table

This program is to copy the elements of the 1-d array A into a 2-d array of k rows and j columns.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
   
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#define ROWS 5
#define COLS 2
using std::cin;
using std::cout;
using std::setw;
using std::endl;
using std::dec;
const int SIZE=10;
int breakflag; 
int i=0;
int j=0;
int k=0;
int n=10;
bool z;
int B[10]={0};
int A[10]={0};
int C[5][2];
bool test (int, int);//func. prototype
int main(){
	 int A[SIZE]={1,4,4,4,5,2,6,7,3,2};
int B[SIZE]={1,4,4,4,5,2,6,7,5,2};

	/*bool test(int A, int B);*/

int *n=B;//pointer to first element of B
int i=2;
int j=4;
cout<<dec<<n<<'\n'<<*n<<endl<<*n+1<<endl<<*(n+1)<<endl<<*n+j<<endl<<*&i<<endl<<*(B+*(B+1))<<endl;
//we want to copy a 1-d array of n=10 elements into a 2-d array of j rows and k columns.
//let j=5 and k=2; the input array and j, k and n will be passed as parameters.

int** pi;

C[0][1]=A[0];
C[0][2]=A[1];
C[1][1]=A[2];
C[1][2]=A[3];
C[2][1]=A[4];
C[2][2]=A[5];
C[3][1]=A[6];
C[3][2]=A[7];
cout<<C[0][1]<<' '<<C[0][2]<<" "<<C[1][1]<<C[1][2]<<C[2][1]<<C[2][2]<<C[3][1]<<C[3][2];
for (int i=0; i<5; i++){
		for (int k=i; k<2; k++){
			C[i][k]	=A[i*5+k];}
		for (int i=0; i<5; i++){
			cout<<dec<<C[i][k];
			cin>>C[i][k];}
}


Result:

002EFDFC
1
2
4
5
2
5
1 4 4452671
Topic archived. No new replies allowed.