Please check the code for inversion count....output is coming wrong

#include <bits/stdc++.h>
using namespace std;
int merge(int a[],int s,int e)
{int temp[1000];
int mid=(s+e)/2;
int i=s;
int j=mid+1;
int k=s;
int cnt =0;
while(i<=mid &&j<=e)
{
if(a[i]<=a[j])
{temp[k]=a[i];
k++;
i++;
}
else
{temp[k++]=a[j++];
cnt+=mid-i+1;
}

}
while(i<=mid)
{temp[k++]=temp[i++];

}
while(j<=e)
{temp[k++]=a[j++];
}
for(i=s;i<=e;i++)
{a[i]=temp[i];
}

return cnt;

}
int inversion(int a[],int s,int e)
{
if(s>=e)
{return 0;
}
int mid=(s+e)/2;
int x=inversion(a,s,mid);
int y=inversion(a,mid+1,e);
int z=merge(a,s,e);
//cout<<x<<" “<<y<<” "<<z<<endl;
return x+y+z;
}
int main() {
int a[1000]={1,5,2,6,3,0};
int n=6;
cout<<inversion(a,0,n-1);
return 0;
}

@imambujsingh08
Please save your code at https://ide.codingblocks.com/ and then share it’s link here.

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.