Output error in inbuilt sort function

bool compare(int a,int b)
{
return a<b;
}

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

sort(a,a+n,compare)//if u want to sort the array in descending order u need a comparator
                    // compare is a function passed in function
for(int i=0;i<n;i++)
{
    cout<<a[i]<<",";
}
return 0;

}

it is producing a wrong output
example- input 3 2 6 1
output 3 2 6 1

I have implemented ur code. It is giving correct output.