0

Inputing iterated values into an empty array.

I would like to store k into a blank array after I would like to be able to print the array in formatted way k x k+1 x k+2...... Thoughts? void numberDivisors (int num) { for (int k=1 ; k <= num ; k++) /// This part works!!! This initializes k and begines counting up into the number inputed!! { int count = 1 ; // initializes a way to count // for (int j = 0 ; j < count ; j++) // { if ( num%k == 0 ) // If K is able to divide the number inputed evenly with no remainder { cout << k << " : "; } } }

3rd Aug 2018, 11:59 PM
Wi$e Xhi8F
Wi$e Xhi8F - avatar
3 Réponses
+ 3
Use std::vector<int> with push_back to add elements
4th Aug 2018, 12:09 AM
Микола Федосєєв
Микола Федосєєв - avatar
+ 1
Seems, it should be numMultiples.push_back(k)
4th Aug 2018, 7:49 AM
Микола Федосєєв
Микола Федосєєв - avatar
0
void numMultiples(int num ) { cin >> num ; vector <int> numMultiples ; for (int k = 1 ; k <= num ; k++ ) { int divMul = num%k ; if ( divMul == 0 ) { numMultiples.push_back(divMul) ; } } } Proper implementation?
4th Aug 2018, 7:35 AM
Wi$e Xhi8F
Wi$e Xhi8F - avatar