Hey everyone out there please help me with this code
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
long n;
cout<<"Enter no. of random numbers to be generated\n";
cin>>n;
int arr1[n];
srand(time(NULL));
for(int i=0;i<n;i++)
{
arr1[i]=rand();
}
int x=0;
int pos=0;
double k=time(NULL);
for(int i=0;i<n-1;i++)
{
x=arr1[i];
for(int j=i+1;j<n;j++)
{
if(x>arr1[j])
{x=arr1[j];
pos=j;}
}
arr1[pos]=arr1[i];
arr1[i]=x;
pos=n+1;
}
double l=time(NULL);
for(int i=0;i<n;i++)
{
cout<<arr1[i]<<"\t";
}
system("pause");
system("cls");
int j=n/2;
cout<<"Median ="<<arr1[j]<<"\n";
cout<<"Time Taken in Processing="<<l-k;
system("pause");
return 0;
}
When I enter a 5 digit number in n the program works perfectly fine
But when I enter a 6 digit number it hangs