+ 2
Divide
how we can divide numbers in c++? example: 12345 => 1,2,3,4,5
4 Answers
+ 2
https://stackoverflow.com/questions/4261589/how-do-i-split-an-int-into-its-digits
"Given the number 12345 :
5Ā isĀ 12345 % 10
4Ā isĀ 12345 / 10 % 10
3Ā isĀ 12345 / 100 % 10
2Ā isĀ 12345 / 1000 % 10
1Ā isĀ 12345 / 10000 % 10
I won't provide a complete code as this surely looks like homework, but I'm sure you get the pattern."
+ 2
This wonāt work on SoloLearn because of glitches with the compiler, but anywhere else, you could convert to string then do it that way:
int num = 12345;
std::string str = std::to_string(num);
cout << str[4] << str[3] << str[2] << str[1] << str[0];
//outputs 54321
0
Thanks guys ;)