Integer's digits. | SoloLearn: Learn to code for FREE!

0

Integer's digits.

I have to write a program (in C++) in wich I have to multiplicate every digit of a "n" number by an "x" number. How do I get the digits of the "n" number? For example: int n; cin >> n; (let's suppose n = 12) How do I get 12's digits?

12/13/2017 6:27:06 PM

Ionut Cicio

2 Answers

New Answer

+9

while (num != 0) {     digit = num %10; num /= 10; } Always been the general formula for getting digits of a number

+1

Convert to string, split string, convert characters back to int.