2021年4月1日星期四

Find the mode of a row and a column of a two-dimensional array

This is what I need to do:

Declare a 5 X 5 array of integers and fill it with random numbers from 1 to 10. Print it row by row. AFTER the array has been filled, ask the user to enter a row and print the mode of that row. Then, ask the user to enter a column and print the mode of that column. Be sure the user knows whether the first row/column is 0 or 1. Check the input and repeatedly prompt until a valid row/column is entered.

And here is my code:

#include <stdio.h>  #include <stdlib.h>  #include <time.h>    int main(void) {      int randNumbers [5][5];    int i,j;    int row,col;      srand(time(NULL));      for (i = 0; i < 5; i++) {        for(j = 0; j < 5; j++) {             randNumbers[i][j]= rand() % 10 + 1;     }   }      for (i = 0; i < 5; i++) {          for (j = 0; j < 5; j++) {             printf("%3i ", randNumbers[i][j]);      }      // move to the next line      printf("\n");    }      printf("\n");      printf("Enter a row (0-4): ");    scanf("%i", &row);      while (row > 4 || row < 0) {        printf("Enter a valid row number: ");        scanf("%i", &row);    }          return 0;  }  

I printed the random numbers and asked the user to enter a row but I don't know how to find the mode.

https://stackoverflow.com/questions/66913300/find-the-mode-of-a-row-and-a-column-of-a-two-dimensional-array April 02, 2021 at 09:06AM

没有评论:

发表评论