Hello @Ankur-Ankur-937479863269311,
Always share your code using online Coding Blocks IDE.
The way you have shared it may cause syntax errors.
STEPS:
- Paste your code on https://ide.codingblocks.com.
- Save your code there.
- Share the URL generated.
Now coming back to your code:
Problem:
After first while loop, the value of n will reduce to 0.
So, second while loop will never execute.Thus, ans will remain 0.
Hence, your code will always return true.
Solution:
Use another variable and assign it the value of n.
Modified Code:
Hope, this would help.
Give a like if you are satisfied.