C Programming Ive got most of this code down I just need to
C Programming:
I\'ve got most of this code down, I just need to fill in the part in bold.
Prompt:
You will need to read from a file the number of people in each section or \"cell\" of memory mall. Then, you should determine which row or column of the grid has the most number of people in it.
Since these numbers represent the number of people in an area, it is guaranteed that all numbers for all input cases are non-negative.
#include <stdio.h>
#define ROWS 20 #define COLS 5
int main() {
// Open the input file and read in the number of cases to process.
FILE* ifp = fopen(\"marketing.txt\", \"r\");
int loop, numCases, best, cur;
int grid[ROWS][COLS], i, j;
fscanf(ifp, \"%d\", &numCases);
// Go through each input case.
for (loop=0; loop<numCases; loop++) {
// Get this input grid.
for (i=0; i<ROWS; i++)
for (j=0; j<COLS; j++)
fscanf(ifp, \"%d\", &grid[i][j]);
// Will store best value for row or column.
best = 0;
/*** FILL IN CODE HERE, TO UPDATE BEST, AS NEEDED. ***/
// Output result.
printf(\"%d\ \", best); }
fclose(ifp); return 0; }
Solution
Program:
--------------------------------------------------------
#include <stdio.h>
#define ROWS 20
#define COLS 5
int main() {
// Open the input file and read in the number of cases to process.
FILE* ifp = fopen(\"marketing.txt\", \"r\");
int loop, numCases, best, cur;
int grid[ROWS][COLS], i, j;
fscanf(ifp, \"%d\", &numCases);
// Go through each input case.
for (loop=0; loop<numCases; loop++) {
// Get this input grid.
for (i=0; i<ROWS; i++)
for (j=0; j<COLS; j++)
fscanf(ifp, \"%d\", &grid[i][j]);
// Will store best value for row or column.
best = 0;
/*** FILL IN CODE HERE, TO UPDATE BEST, AS NEEDED. ***/
/***Code: ***/
for (i=0; i<ROWS; i++)
{
for (j=0; j<COLS; j++)
{
cur = grid[i][j];
if (cur > best){best = cur;}
}
}
// Output result.
printf(\"%d\ \", best); }
fclose(ifp); return 0; }

