G
G
Gokilla2018-03-30 03:55:51
C++ / C#
Gokilla, 2018-03-30 03:55:51

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

2 answer(s)
R
res2001, 2018-03-30
@res2001

Discover the operation of taking the remainder of the division -% (in your case by 10), with its help your task is solved trivially.

A
Alexander Taratin, 2018-03-30
@Taraflex

#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 question

Ask a Question

731 491 924 answers to any question