[Solved] the output is throwing large numbers [closed]


you are getting bigger numbers because on this line

for(int i=0;i<n;i++){
    cin>>arr[n];
}

You are changing the value on arr[n] (that doesn’t exist because you array goes from 0 to n-1). Basically you are not changing any value inside the array so its using trash values that were stored on the memory.

The fix to not get those big number is change the line cin>>arr[n]; to cin>>arr[i];. I didnt test your code to check if you will have a correct answer to the problem that you are trying to solve but the big numbers will go away.

Cheers!

1

solved the output is throwing large numbers [closed]