You’ve got an out-of-bounds access, which is Undefined Behaviour:
int *a = new int [n];
for(int i=1;i<=n;i++){
cin >> a[i];
(when i == n
).
Edit:
There are at least two more that I can spot.
2 Likes
I got it.
Edit : Thank you very much program is running fine now
1 Like