i want to pass array to recursive function , but i need to keep all the arrays
output :
1 0 0 0 0
1 2 0 0 0
1 2 3 0 0
1 2 3 0 0
1 2 3 0 0
when i return to the previous step i want to use array : 1 2 0 0 0
second return : 1 0 0 0 0
not this one : 1 2 3 0 0
my goal is to see output like this
1 0 0 0 0
1 2 0 0 0
1 2 3 0 0
1 2 0 0 0
1 0 0 0 0
.
#include<iostream>
using namespace std;
int a[100];
void go (int a[100],int x)
{
a[x]=x;
for(int i=1;i<=5;i++)cout<<a[i]<<" ";cout<<endl;
if(x==3)return;
go(a,x+1);
for(int i=1;i<=5;i++)cout<<a[i]<<" ";cout<<endl;
}
main()
{
go(a,1);
}
it uses only 1 array :/ i need it to create another arrays 'a' and when it returns to previous step not to use the last array but the one which was remembered on that step
please help :(