/* Write a program that performs the following: Declares a two dimensional array of integers of size 3X4 (3 rows and 4 columns) Fills the array with the random generated numbers 0, 1, 2, 3, and 4 using function we wrote in class. Prints the random array using function we wrote in class Calculates the frequencies of each number in the array and prints the result with an appropriate message. */ #include #include #include #define ROW 3 #define COL 4 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); void print_array1D(int A[], int size); int main(){ srand(time(NULL)); int A[ROW][COL],i,j, freq[5]={0}; make_random_array2d(A, ROW, COL, 0,4); printf("random array is\n"); print_array(A, ROW, COL); for (i = 0; i < ROW; i++){ for (j = 0; j < COL; j++){ freq[A[i][j]]++; } } printf("frequencies are\n"); print_array1D(freq,5); return 0; } 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); } } } void print_array1D(int A[], int size){ int i; for(i=0;i