answersLogoWhite

0


Best Answer

Repeatedly divide the number by 10 and store the remainder (the modulo).

By way of an example, if the number were 12345:

12345 % 10 = 5 (first digit)

12345 / 10 = 1234

1234 % 10 = 4 (second digit)

1234 / 10 = 123

123 % 10 = 3 (third digit)

123 / 10 = 12

12 % 10 = 2 (fourth digit)

12 / 10 = 1 (fifth digit)

This algorithm forms the basis of number reversals. The following function demonstrates the most efficient way of reversing any number in the range -2,147,483,648 to 2,147,483,647, inclusive.

int RevNum( int num )

{

const int base = 10;

int result = 0;

int remain = 0;

do

{

remain = num % base;

result *= base;

result += remain;

} while( num /= base);

return( result );

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you separate digits in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

C plus plus program to print sum of uppercase digits?

Good luck. I don't think it is possible, since there is no such thing called upper case digits.


What is the Aram strong number in c plus plus?

If the sum of squares of digits of a number equals to the number itself, then that number is called an aram strong number.


What is an arrangement of numbers that separate the ones digits from the other digits?

2984, 2980


What Lead to C C plus plus and java?

(C and Lisp, ... data type") was adopted by many later languages, such as ALGOL 68 (1970), Java, and C#. ... C++ has a separate Boolean data type ( 'bool' ), but with automatic conversions from ... "Report on the Algorithmic Language ALGOL 68


What does 5 D in a Z C stand for?

"5d in a z c" means 5 Digits in aZip Code.


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c


B plus b plus b plus c plus c plus c plus c equals?

b + b + b + c + c + c + c = 3b + 4c


Symplify c plus c plus c plus c?

4c


C plus plus program to count digit in a string?

Use the following function to count the number of digits in a string. size_t count_digits (const std::string& str) { size_t count = 0; for (std::string::const_iterator it=str.begin(); it!=str.end(); ++it) { const char& c = *it; if (c>='0' && c<='9'); ++count; } return count; }


What is c plus c plus c plus c plus c?

c + c + c + c + c = 5 * c.


ABC plus ABC equals CDD then what does ABC equals in numbers?

Assuming A, B, C and D all represent different digits then ABC = 183 .