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 << " : "; } } }
3 Antworten
+ 3
Use std::vector<int> with push_back to add elements
+ 1
Seems, it should be
numMultiples.push_back(k)
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?