I was wondering how I could store the factors in an array instead of displaying them.
For example:
Now, if you put in "216" as u, it will display: "2*2*2*3*3*3"
Instead, I would want them stored in an array(let's say its called myArray) as:
myArray[0]=2
myArray[1]=2
myArray[2]=2
myArray[3]=3
myArray[4]=3
myArray[5]=3
How can I do that. If possible, modify the code given. If not, please post a new code.
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
// function implementation goes here
int main()
{
unsigned h = 216;
std::vector<int> s;
Factorize(h,s);// now vector s containe the factorization of 216
// displaying each element in vector s, seperated by a comma
std::ostream_iterator<int> o(std::cout,",");
std::copy(s.begin(),s.end(),o);
char c[10];
std::cin.getline(c,10);
}