Sir there is small error in my code and i wont able to find it

#include
#include
using namespace std;
void printarray(int a[],int k )
{
for(int i=0;i<k+1;i++)
{
cout<<a[i]<<" ";
}
}
void mergesort(int a1[],int a2[],int n)
{
int a[10000];
int k=0;
int i=0;
int j=0;
while(j!=n-1||i!=n-1)
{
if(a1[i]>a2[j])
{
a[k]=a2[j];
k++;
j++;
}
else
{
a[k]=a1[i];
k++;
i++;
}
}
if(j<n)
{
while(j<n)
{
a[k]=a2[j];
k++;
j++;
}
}
else
{
while(i<n)
{
a[k]=a1[i];
k++;
i++;
}
}
printarray(a,k);

}
int main()
{
int n,a1[1000],a2[1000];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a1[i];
}

for(int i=0;i<n;i++)
{
	cin>>a1[i];
}

mergesort(a1,a2,n);
cout<<endl;

return 0;

}

@Harshit-Kumar-2577121455897279,
Please share a Coding Blocks IDE link of your code.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.