Code running successfully in other compilers but showing error in this compiler


#1

The program code pasted below is running successfully in other compilers but showing errors in this compiler.Can anyone tell me what is the reason for it.
#include

using namespace std;
int sort(int arr[],int n,int k)
{
int temp,i,j;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[j]<arr[i])
{
temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
}
}
}
}

int main()
{
int n,k,i;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
//cout<<"Enter the value of K ";
cin>>k;
sort(arr,n,k);
n = k-1;

    cout<<arr[n]<<" ";

return 0;

}


#2

It’s mentioned in the question that you can’t modify the array maybe that’s why u r getting an error.