Don’t know whether you were in hurry or not…but reason is quite simple…
in the loop statement indexing is problem according to your code you are accessing arr[n] i.e. (n+1)th element of array (remember indexing is always 0 based in cpp), and since you’ve allocated memory for n elements only it’s showing runtime error.
I guess it must be a SIGSEGV runtime error(it is caused due to invalid memory access).
Hope it helped! Cheers!