Why segmentation fault?

code: https://ide.codingblocks.com/s/228021

Hello @adityakaunhai,

There are mistakes in your code.
I have corrected them all:


Refer to comments for better understanding.

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

1 Like

how to debug code in code blocks? dry running the code is hectic and also sometimes it’s not easy

Hello @adityakaunhai,

What do i do?

  1. Read the question again and see if i have missed something.

  2. Check if the constraints are being followed properly.

  3. Use print statements (i.e. cout) to see the flow of the code.

  4. Comment different modules(functions) to identify which module is causing error.

  5. Test your code for different possible test cases you can think of.

  6. At last, I dry run the code.

Hope, this would help.