/* Since variable length vectors are not a native type in C, we design

* a simple object that is a vector of integers.

*/

typedef struct _vector {

int *array; // the array of integers

int num; // number of integers in the array

int max; // the size of the current allocation

} *Vector;

/**

* Create a new Vector instance.

*/

Vector newVector()

{

return(calloc(1, sizeof(struct _vector)));

}

/**

* Append integer num to Vector vect

*/

void appendToVector(Vector vect, int num)

{

if (vect != null) {

// Grow the array of integers in chunk sizes of 100, if we run out of room

if (vect.numItems >= vect.allocItems)

vect.array = int * realloc(vect.array, (vect.allocItems += 100)*sizeof(int));

// Append the number to the array

vect.array[numItems++] = num;

}

}

/* Determining the multiples and remainder of X are easy,

* especially using integer division (/) and modular division (%).

* However, since you want to enumerate each multiple in the vector,

* we use simple subtraction in a loop, then append the remainder.

*/

int num = 50;

int x = 32;

Vector vect = newVector();

while (num > x) {

appendToVector(vect, x);

num -= x;

}

if (num)

appendToVector(vect, num);

* a simple object that is a vector of integers.

*/

typedef struct _vector {

int *array; // the array of integers

int num; // number of integers in the array

int max; // the size of the current allocation

} *Vector;

/**

* Create a new Vector instance.

*/

Vector newVector()

{

return(calloc(1, sizeof(struct _vector)));

}

/**

* Append integer num to Vector vect

*/

void appendToVector(Vector vect, int num)

{

if (vect != null) {

// Grow the array of integers in chunk sizes of 100, if we run out of room

if (vect.numItems >= vect.allocItems)

vect.array = int * realloc(vect.array, (vect.allocItems += 100)*sizeof(int));

// Append the number to the array

vect.array[numItems++] = num;

}

}

/* Determining the multiples and remainder of X are easy,

* especially using integer division (/) and modular division (%).

* However, since you want to enumerate each multiple in the vector,

* we use simple subtraction in a loop, then append the remainder.

*/

int num = 50;

int x = 32;

Vector vect = newVector();

while (num > x) {

appendToVector(vect, x);

num -= x;

}

if (num)

appendToVector(vect, num);