I need this array to swap the 1st row for the 2nd and the 2nd for the 3rd but then i need the third row to be set to the original first row with the number of gates and then the first row in reverse order then the 2nd row. For instace if the number of gates is 4.

1st row=2,1
2nd row=1,3,1,2,1
3 should be 2,1(1st),4(number of gates),1,2(1st in reverseoder),1,3,1,2,1(2nd row)

so the solution should be 2,1,4,1,2,1,3,1,2,1

I can get all of it to work but getting the 3rd row to include the combination of the previous rows. Here is my code so far:
Code:
#include <stdio.h>
#include<iostream.h>
#include<math.h>

int main(int argc, char *argv[])
{

  int numberofgates,t,numgates;
  int A[3][100]={{1},{2,1},{1,3,1,2,1}};
  int i,j;
  cout<<"enter the gates"<<endl;
  cin>> numgates;
  numberofgates=(int)ceil((double)(2*(pow(2,numgates)-1))/3);
  t=((int)ceil((double)(2*(pow(2,numgates-2)-1))/3));

  //print array A
  for(i=0;i<3;i++)
  {
    for(j=0;j<numberofgates;j++)
      cout<< "A["<<i<<"]["<<j<<"]=" <<A[i][j]<< " ";

      cout<<endl;
   }

  //copy row 2 to row 1
  cout<<"\n\nCopy row 2 to row 1\n\n ";
  for(i=0;i<numberofgates;i++)
    A[0][i]=A[1][i];


    //print the array A, again
    cout<<"\n\n";
    for(i=0;i<3;i++)
      {
        for(j=0;j<numberofgates;j++)
          cout<<"A["<<i<<"]["<<j<<"]=" <<A[i][j]<< " ";
          cout <<endl;
       }
//copy row 3 to row 2
  cout<<"\n\nCopy row 3 to row 2\n\n ";
  for(i=0;i<numberofgates;i++)
    A[1][i]=A[2][i];


    //print the array A, again
    cout<<"\n\n";
    for(i=0;i<3;i++)
      {
        for(j=0;j<numberofgates;j++)
          cout<<"A["<<i<<"]["<<j<<"]=" <<A[i][j]<< " ";
          cout <<endl;
       }

//copy solution to row 3
  cout<<"\n\nSolution\n\n ";
  for(i=0;i<numberofgates;i++)
  {
    for(j=0;j<=t;j++) {
      A[2][j]=A[0][j];
      }

         for(j=j;j<numberofgates;j++){
           A[2][j]=A[0][j];
          }

    }


    //print the array A, again
    cout<<"\n\n";
    cout<<"the solution is\n";
    for(i=0;i<3;i++)
      {
        for(j=0;j<numberofgates;j++)
          cout<<"A["<<i<<"]["<<j<<"]=" <<A[i][j]<< " ";
          cout <<endl;
       }
   cin>>i;
   }