Why it is not giving correct output?
@cbcao263
You cannot get the length of the number/ no of digits using sizeof() operator.
I have made the required changes in your code.
Then what is the use of to_string.
Another method to use without string is to take a counter and for every digit I will do count++.
Will it be Okay too.
@cbcao263 You can get the length by converting it into string and then getting the length of the string. Yes you can use the counter as well. while(n>0) counter++,n = n/10;
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.