the code snippet below takes an an integer (i.e. number) from the user and prints the count of all the digits in that number, however, if I enter a number contains 0 somewhere, it gets out of the while loop immediately (because of the while loop condition). I tried fixing this bug but I could not. Could you please help me out fixing it. Thank you.
int count = 0;
int rem = number % 10;
while(rem != 0) {
number /= 10;
++count;
rem = number % 10;
}//end while
printf("The count is %d", count);
No code need to be shared, if you can walk me through it by text, that would appreciated.
Thank you.
Perhaps it should be:
You don’t seem to need the other stuff (
remet al) unless you plan on doing more than just counting digits. And at any rate, you probably wantrem = number % 10;before the division.