# 李錄不客氣 ``` #include <stdio.h> #include <stdlib.h> #include <time.h> #define SIZE 10 + 1 // function to print the dimensional array void printArray(int twoDimsional[SIZE][SIZE], int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { printf("%d ", twoDimsional[i][j]); } printf("\n"); } } // function to print the menu void printMenu() { printf("\nPlease choose which action you want to perform: (Enter [1/2/3])\n"); printf("1: Min Pooling\n"); printf("2: Multiples of X\n"); printf("3: Exit()\n"); } // function to do the min pooling void minPooling(int twoDimsional[SIZE][SIZE], int n) { int smallest = 100; for (int i = 0; i < n; i++) { smallest = 101; for (int j = 0; j < n; j++) { if (twoDimsional[i][j] < smallest) smallest = twoDimsional[i][j]; } printf("%d ", smallest); } } // function to find the multiple of x void multiplesOfX(int twoDimsional[SIZE][SIZE], int n, int x) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (twoDimsional[i][j] % x == 0) printf("matrix[%d][%d]: %d\n", i, j, twoDimsional[i][j]); } } } int main() { srand(time(NULL)); // declare the variables int size, mode, x, mat[SIZE][SIZE] = {0}; // get the size of the matrix printf("Input the X of the matrix (2~10): "); scanf("%d", &size); while (size < 2 || size > 10) { printf("Wrong matrix size, please select again: "); scanf("%d", &size); } // initilize the matrix for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { mat[i][j] = rand() % 99 + 1; } } // print the matrix printf("\nThe initial %d*%d matirx: \n", size, size); printArray(mat, size); printMenu(); scanf("%d", &mode); while (mode < 1 || mode > 3) { printf("The input number is not within the range. Try again: "); scanf("%d", &mode); } while (mode != 3) { if (mode == 1) { // do the min pooling in mode 1 minPooling(mat, size); // return to the menu printMenu(); scanf("%d", &mode); while (mode < 1 || mode > 3) { printf("The input number is not within the range. Try again: "); scanf("%d", &mode); } } else if (mode == 2) { printf("Please enter the x: "); scanf("%d", &x); while (x < 1) { printf("The input number should be positive. Try again: "); scanf("%d", &x); } // find the multiple of x in mode 2 multiplesOfX(mat, size, x); // return to the menu printMenu(); scanf("%d", &mode); while (mode < 1 || mode > 3) { printf("The input number is not within the range. Try again: "); scanf("%d", &mode); } } } // exit the program in mode 3 printf("End Program"); } ```