Converting 1-d array to 2-d matrix ! Reply ASAP.

This program is not working. The question and its answer is there below.
Please tell what is wrong with this program ?

Q.Write a program using user-defined function which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format: If the array is 1,2,3,4,5,6, the resultant 2D array is
1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0


Ans.
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
#include<iostream>
using namespace std;

int two_print(int x, int one[999])
{
    int two[999][999], q=x, z=x;
    for(int k=0; k<x; k++)
    {
        q--;
        for(int j=q; j>=0; j--)
        {
            two[k][j]=one[k];
        }
    }
    for(int m=0; m<x; m++)
    {
        for(int n=z; n<x; n++)
        {
            two[m][n]=0;
        }
        z--;
    }
    cout<<"The elements in configured matrix form:\n";
    for(int e=0; e<x; e++)
    {
        for(int f=0; f<x; f++)
        {
            cout<<two[e][f]<<"  ";
        }
        cout<<endl;
    }
}

int main()
{
    int one_print[999], len, len_user;
    cout<<"Enter the size of the array: "; cin>>len_user; cout<<"\n";
    cout<<"Enter the elements of the array:\n";
    for(len=0; len<len_user; len++)
    {
        cin>>one_print[len];
    }
    two_print(len, one_print);
    return(0);
}

Last edited on
You should have explained the "not working" with more detail.

Nevertheless, on line 12 you assign same element from 'one'. That, I believe, is the logical error.
I am using codeblocks.
This code force closes after accepting the series for 1-d array.
I have already made a lot of changes and also tried to run it on an online compiler but it still does not work.
Topic archived. No new replies allowed.