views:

65

answers:

1

A program in c++ that accept an integer array and its size as arguments and assign the elements into a 2-D array of integers. for ex: if the array is 1,2,3 The resultant 2-D array is given by

1 2 3
1 2 0
1 0 0

+2  A: 

can you please give me the logic

The logic is very simple. Let n be the size of the 1D array.

create a 2d array of size n x n
for y in [0, n)
    copy elements [0, n-y) from the 1D array to line y
    set elements [n-y, n) to 0 in line y

...and that's basically it, where [begin, end) denotes a half open range.

FredOverflow
please give me the program
anurag18294
@anurag: Where exactly are you having trouble transforming my pseudo code into C++? It's fairly straightforward.
FredOverflow