# Thread: How to separate the number with spaces in between using while loop and power function

1. ## How to separate the number with spaces in between using while loop and power function

Dear all,
How do I separate number with 5 spaces in between the numbers without reversing the number using while loop and <math.h> pow function?

1. User will be asked to input n-number of numbers
2. User will be asked to enter the numbers
3. Print out the numbers without using arrays but only basic while loop and pow function.

Hope to get some help, thank you! 2. I don't understand your question. Why are you worried about the numbers possibly becoming "reversed"? And how does the pow function come into it?

Show example input and output. 3. Originally Posted by john.c I don't understand your question. Why are you worried about the numbers possibly becoming "reversed"? And how does the pow function come into it?

Show example input and output.
Hi John, attached to this message is my code and my output. Do take a look thank you.  4. If I understand correctly, you want to print out the digits of the number in the correct order, using the pow function (presumably with powers of 10).

Since you have the number of digits (which I guess we are assuming is true, since there's no guarantee that's how many digits the user enters), then number / pow(10, num_digits - 1) stored in an int would give the first digit. number / pow(10, num_digits - 2) would give a value ending in the second digit of number, so taking that % 10 would give the second digit. Etc.

log10 could be used to determine the number of decimal digits in number without needing to trust the user. Popular pages Recent additions math.h, numbers, pow, separating integers, while loop 