Can anyone tell me why i am getting run time error?

In tubosort the question is this
Given the list of numbers, you are to sort them in non decreasing order
Input
t – the number of numbers in list, then t lines follow [t <= 10^6]. 
Each line contains one integer: N [0 <= N <= 10^6]
Output
Output given numbers in non decreasing order.
Example
Input:
5
5
3
6
7
1
Output:
1
3
5
6
7

my coding is this

#include< iostream>
using namespace std;
int main()
	{	int n,t,k[40];
		cin>>n;
		for(int i=0;i< n;i++)
		cin>>k[i];
		for(int j=0;j< n;j++)
	{	int min=k[j],pos=j;
		for(int l=j+1;l<n;l++)
		{	if(min>k[l])
			{min=k[l];
			pos=l;} }
		t=k[j];
		k[j]=k[pos];
		k[pos]=t;
	}
	for(int m=0;m< n;m++)
	cout<< k[m]<<"\n";
	return 0;
	}
i am getting a runtimerror, what mistake is in my code?

you are getting RE because number if numbers( n ) can be >40 but you are taking only an array of size 40 which can hold maximum 40 elemesnts,so you should change your size of array to contain all n elements. Since n can 10^6 so you can declare something like k[1000005].