+ 2
Divide
how we can divide numbers in c++? example: 12345 => 1,2,3,4,5
4 Antworten
+ 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 ;)