Answer the question
In order to leave comments, you need to log in
Split number into digits c++?
It is required to divide the number into digits, i.e. 15= 1+5, write to the array a[0]=1,a[1]=5 I solved this problem, but I messed up something and it turned out difficult, maybe there is some function from the language? You need a number of credits and winnings for this.
Answer the question
In order to leave comments, you need to log in
Discover the operation of taking the remainder of the division -% (in your case by 10), with its help your task is solved trivially.
#include <iostream>
#include <string>
int main()
{
for(auto && v : std::to_string(15)){
std::cout << v - '0' << "|";
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question