Answers for "program to convert int to int array c++"

C++
0

program to convert int to int array c++

#include <iostream>
#include <vector>
using namespace std;

vector <int> integerToArray(int x)
{
    vector <int> resultArray;
    while (true)
    {
    resultArray.insert(resultArray.begin(), x%10);
    x /= 10;
    if(x == 0)
        return resultArray;
    }
}

int main()
{
    vector <int> temp = integerToArray(1234567);
    for (auto const &element : temp)
        cout << element << " " ;
    return 0;
}

//outputs 1 2 3 4 5 6 7
Posted by: Guest on July-27-2021

Browse Popular Code Answers by Language