/*Write a function int replace_odd (int A[][COL], int num_rows, int num_cols) that finds and returns the amount of the odd elements among the elements of the array A AND replaces all odd numbers with 0. Write a program that randomly generates 3 two-dimensional arrays of size 3X4 (3 rows and 4 columns) each (range of the numbers between 0 and 10). The program prints randomly generated arrays. The program calls function replace_odd for each array, prints the number of odds in each array and prints an array after replacement was done. */ #include #include #include #define ROW 3 #define COL 4 int replace_odd(int A[][COL], int num_rows, int num_cols); void print_array(int A[][COL], int num_row, int num_col); void make_random_array2d(int A[][COL], int num_row, int num_col, int min, int max); int main(){ srand(time(NULL)); int A[ROW][COL],i; for(i=0;i<3;i++){ make_random_array2d(A,ROW, COL, 0,10); printf("array %d BEFORE REPLACE \n",i+1); print_array(A, ROW, COL); printf("number of odds %d\n",replace_odd(A, ROW, COL)); printf("array %d AFTER \n",i+1); print_array(A, ROW, COL); } return 0; } int replace_odd(int A[][COL], int num_rows, int num_cols){ int i,j, count=0; for (i = 0; i < num_rows; i++){ for (j = 0; j < num_cols; j++){ if(A[i][j]%2!=0){ A[i][j]=0; count++; } } } return count; } void print_array(int A[][COL], int num_row, int num_col){ int i; /* row counter */ int j; /* column counter */ for (i = 0; i < num_row; i++){ for (j = 0; j < num_col; j++){ printf("%d ", A[i][j]); } printf("\n"); } } void make_random_array2d(int A[][COL], int num_row, int num_col, int min, int max){ int i; /* row counter */ int j; /* column counter */ for (i = 0; i < num_row; i++){ for (j = 0; j < num_col; j++){ A[i][j]=min+rand()%(max-min+1); } } }