Write a function that fills in a given matrix with the given numbers so that the sum of all columns and all rows should be equal to the same number. The prototype for the function should be

void fillMatrix(int mat[][MAXSIZE], int numbers[], int rowSize, int colSize, int sum);

For example, if we call fillMatrix

int m[3][3];
int v[] = {1, 2, 0, 3, 4, 5, 7, 8, -3};
fillMatrix(m, v, 3, 3, 9);

The matrix m is filled by the function as follows
3 1 5
2 0 7
4 8 -3


The MAXSIZE is a #define and it should be taken as 100, which means that 2D matrix can be at most 100 by 100.

Run your function with the following numbers arrays and sum values. Print your results.
• numbers = {18,14,12, 10,8,8,6,6,6,6,6,4,4,4,4,2,2,0,0,0,0,-2,-2,-2,-2,-4,-6,-6,-6,-10,-10, -10, -10, -10, -10,-18}, sum=2, rowsize=6, colsize=6
• numbers = { 1,11,-7,-3 11, 10, -10, -9, -1, -10, 6, 7, -9, -9, 13, 7}, sum=2, rowsize=4, colsize=4
• numbers = {-44,-22,-12,-6,-5,-4,1,5,5,13,-22,-4,-30,-11,-10,-8,-5,-1,1,1,4,4,4,34,-23, -5, 5,16,7, 1,-14,10,8,-6,3,-19,-8,3,4,11,-15,-9,10,-5,-4,14,3,-9,0,-5,0,-9,11,-5,4,8,-41,11,-5,-5,2,-14,-2, 14,14,-19,6,-15,1,0,-14,-19,3,14,-15,36,-9,-9,-5,-9,13,-25,14,-9,4,-3,14,-3,1,-12,-7,7,-7,-8, -3,-12,9,21,11,-9,3,-7,-87,-3,13,10,21,-7,10,-15,-15,-6,1,41,4,7,6,-52,-15,41,10,-15,-7,-14,-4, 4,37,-14,-8,7,-15,4,13,12,-3,-33,-1,-12,9,-10,7,13,12,-12}, sum=-17, rowsize=12, colsize=12

i can not produce a fast algorithm for the question,please help me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.