Suggested changes for this code

#include
using namespace std;
void mergeArrays(int a[],int b[], int n, int c[]){
int i=0,j=0, k=0;
while(i<n && j<n){
if(a[i]< b[j]){
c[k++]=a[i++];
}else{
c[k++]=b[j++];
}
}while(i<n){
c[k++]=a[i++];
}while(j<n){
c[k++]=b[j++];
}
}
int main() {
int n;
cin>>n;
int a[1000]={0};
int b[1000]={0};
for(int i=0; i<n;i++){
cin>>a[i];

}
for(int j=0;j<n;j++){
	cin>>b[j];
}
int c[2000];
mergeArrays(a,b,n,c);
int mid=(c[0]+c[n+n-1])/2;
cout<<mid;



return 0;

}

@neelrai906
hello neel,
formula for median is wrong .
if n is odd then it will c[n/2]
otherwise
it will be (c[n/2]+c[n/2-1])/2

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.