Question
Im having trouble coding a function in C programming. Here is the required function and an example output: Here is my code, I have bolded
Im having trouble coding a function in C programming. Here is the required function and an example output:
Here is my code, I have bolded the part that needs fixing, everything else is fine:
#include
#define COL 20 #define ROW 20
void PopulateArray2DUnique(int A[][COL], unsigned int rowsize, unsigned int colsize, int min, int max) { srand(time(NULL)); //Seeds for rand() int i, j; for (i = 0; i
void DisplayArray(int A[][COL], unsigned int rowsize, unsigned int colsize) { int i, j; for (i = 0; i
int FindLargest(int A[][COL], unsigned int rowsize, unsigned int colsize) { int max = 0; for (int i = 0; i max) max = A[i][j]; } } return max; }
int FindColumnSum(int A[][COL], unsigned int rowsize, unsigned int colsize, unsigned int col_to_sum) { int Col_sum = 0; for (int i = 0; i
int Sort2DArray(int A[][COL], unsigned int rowsize, unsigned int colsize, unsigned int Order) { int n = colsize; int temp[n * n]; int k = 0; if (Order == 1) { for (int i = 0; i
} } } } } }
int CopyArray2D(int A[][COL], int B[][COL], unsigned int rowsize, unsigned int colsize) { for (int i = 0; i
int CopyArray2DSpiral(int A[][COL], int B[][COL], unsigned int rowsize, unsigned int colsize) { int i, k = 0, l = 0; while (k
/* Print the last column from the remaining columns */ for (i = k; i
/* Print the last row from the remaining rows */ if (k = l; --i) { B[colsize - 1][l] = A[rowsize - 1][i]; } rowsize--; }
/* Print the first column from the remaining columns */ if (l = k; --i) { B[rowsize - 1][k] = A[i][l]; } l++; } } }
int main() {
int row, col;
int array[ROW][COL], ArrayB[ROW][COL];
/*Input number of rows and columns*/ printf("Enter row size: "); scanf("%d", & row); while (row 20) //Validate input { printf("Enter valid row size: "); scanf("%d", & row); } printf("Enter column size: "); scanf("%d", & col); while (col 20) //Validate input { printf("Enter valid column size: "); scanf("%d", & col); }
PopulateArray2DUnique(array, row, col, 1, 99); printf(" The matrix is: "); DisplayArray(array, row, col);
int largest = FindLargest(array, row, col); printf(" Largest Element is: %d ", largest);
int sum = FindColumnSum(array, row, col, 0); printf(" Sum of the column 0 is: %d ", sum);
CopyArray2D(array, ArrayB, row, col);
Sort2DArray(array, row, col, 1); printf(" Matrix after sorting in ascending order: "); DisplayArray(array, row, col);
CopyArray2D(array, ArrayB, ROW, COL); printf(" Array A copied into B: "); DisplayArray(ArrayB, row, col);
CopyArray2DSpiral(array, ArrayB, row, col); printf(" Matrix after 2D Spiral Copy: "); DisplayArray(ArrayB, row, col); return 0; }
int CopyArray2DSpiral (int Al [COL1, int BI1 [COLl, unsianed int rowsize, unsigned int colsize); Copy the contents of array A into array B of the same size such that the contents of B would be exactly the contents of A except they will be in a clockwise spiral sorted order. e.g. copying A into B with Spiral etFects: A: B: 1 2 3 4 5 6 > 8 9 4 Hint: you may consider sorting A first before starting. Note that your function should work for any size array up to 20x20 CopyArray2D from A to B, then Display B: 12 15 25 28 33 34 41 45 55 81 91 94 CopyArray2DSpiral from A to B, then Display B: 12 15 25 28 81 91 94 33 55 45 41 34 -- end run HintStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started