Does anyone know if it's possible to count the number of digits in an integer? One of my friends recommended log10 or something but I can't figure it out.
Redneon
Does anyone know if it's possible to count the number of digits in an integer? One of my friends recommended log10 or something but I can't figure it out.
Redneon
the number of digits in a base 10 number is equal to the number of times you multiply 1 times 10 to get to the same length (plus one to account for the first digit). So essentially, log 10 is that number. your buddy is correct.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
Here you go should work as you need
i forget why but for some reason when usign a while loop. the loop will execute one time after the specified stopping pointCode:int number, temp, print; cin>>number; print = 0; while (temp != 0) { temp = number % 10; number = number / 10; print++; } print = print -1; // reason for this below cout<<print;
IE it would count one more then needed.
try it without this and you'll see what i mean
Last edited by Iamien; 08-18-2003 at 04:26 PM.