How can fix run time error in this

Hello @AjAy03,

Run time error is one of the common errors you would face with your code in future.
So, let’s understand the reasons that lead to run time error:

  1. Invalid memory access during run-time.
  2. Accessing linked list nodes that do not exist.
  3. Dividing by zero.
  4. Large allocation of memory together/Large Static Memory Allocation.
  5. Making a silly mistake.

In your code, you are facing the issue mentioned in point 1.
How, are you so sure that there would not be more than 100 elements in the array?

a[100]

Solution:

cin >> n;
int a[n];

Hope, this would help.
Give a like, if you are satisfied.

1 Like

Thanks for detailed explanation :slightly_smiling_face: