Question: C PROGRAMMING The program uses both files and two dimensional arrays. The Problem Statement Business is going well for your friend, who is selling discounts

C PROGRAMMING

The program uses both files and two dimensional arrays.

The Problem Statement

Business is going well for your friend, who is selling discounts to area clubs and restaurants, which means that business is going well for you!

Both of you have decided that you'll advertise on memory mall, which is roughly arranged as a rectangle. There's not enough time before a football game to hand flyers to everyone arranged on the mall. Therefore, you will only be able to walk through one "row" or "column" of the huge grid for advertising purposes.

Naturally, you'd like to give flyers to as many people as possible as you make your single walk through.

Program Setup

A scaffold of the solution has been created for you:

#include  #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 

Place your solution in the designated area of the scaffold.

Memory mall is arranged like a 20 x 5 grid of tailgating locations. A representation of memory mall has been created using a two dimensional array. 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.

Example

This example is on a smaller grid to illustrate the idea. Suppose the following is our input grid.

200 20 500 19 25 44 5 16
50 30 400 15 80 93 2 14
19 40 600 0 30 18 92 19

Each number represents the number of people tailgating in that cell. If we select the third column shaded blue, we would advertise to 1500 people. This is more than if we chose any of the other columns or rows.

Input File Format

The first line of the input file contains a single positive integer, n (n 1000), representing the number of grids to process.

This is followed by n 5x20 grids of integers.

Sample Run

After you add your code to designated location in the scaffold, run your program using the input file marketing.txt. Your output should match the output in marketing.out.

Input file should contain:

25

100 100 100 100 100

1 1 2 1 2

2 2 3 4 5

3 5 5 3 3

4 2 2 0 0

5 0 0 2 2

6 1 1 1 1

7 4 3 2 1

8 4 3 2 1

9 10 10 10 10

10 4 5 4 2

11 4 3 2 1

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

100 100 100 100 100

1 1 2 1 2

2 2 3 4 5

3 5 5 3 3

4 2 2 0 0

5 0 0 2 2

6 1 1 1 1

7 4 3 2 1

8 4 3 2 1

9 10 10 10 10

10 4 5 4 2

11 4 3 2 1

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

230 13 14 15 16

1 1 2 1 2

100 100 100 100 100

2 2 3 4 5

3 5 5 3 3

4 2 2 0 0

5 0 0 2 2

6 1 1 1 1

7 4 3 2 1

8 4 3 2 1

9 10 10 10 10

10 4 5 4 2

11 4 3 2 1

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

3 5 5 3 3

4 2 2 0 0

5 0 0 2 2

6 1 1 1 1

7 4 3 2 1

8 4 3 2 1

9 10 10 10 10

10 4 5 4 2

11 4 3 2 1

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

4 2 2 0 0

5 0 0 2 2

6 1 1 1 1

7 4 3 2 1

8 4 3 2 1

9 10 10 10 10

10 4 5 4 2

11 4 3 2 1

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

5 0 0 2 2

6 1 1 1 1

7 4 3 2 1

8 4 3 2 1

9 10 10 10 10

10 4 5 4 2

11 4 3 2 1

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

6 1 1 1 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

7 4 3 2 1

8 4 3 2 1

9 10 10 10 10

10 4 5 4 2

11 4 3 2 1

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

6 1 1 1 1

7 4 3 2 1

8 4 3 2 1

9 10 10 10 10

10 4 5 4 2

11 4 3 2 1

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

8 4 3 2 1

9 10 10 10 10

10 4 5 4 2

11 4 3 2 1

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

9 10 10 10 10

10 4 5 4 2

11 4 3 2 1

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

10 4 5 4 2

11 4 3 2 1

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

11 4 3 2 1

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

11 4 3 2 1

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

12 1 2 3 4

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

12 1 2 3 4

11 4 3 2 1

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

13 4 3 2 1

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

13 4 3 2 1

12 1 2 3 4

11 4 3 2 1

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

14 4 3 2 1

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

14 4 3 2 1

13 4 3 2 1

12 1 2 3 4

11 4 3 2 1

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

15 1 2 3 4

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

15 1 2 3 4

14 4 3 2 1

13 4 3 2 1

12 1 2 3 4

11 4 3 2 1

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

16 13 3 4 4

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

16 13 3 4 4

15 1 2 3 4

14 4 3 2 1

13 4 3 2 1

12 1 2 3 4

11 4 3 2 1

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

17 100 100 100 182

18 17 18 19 20

228 13 14 15 16

17 100 100 100 182

16 13 3 4 4

15 1 2 3 4

14 4 3 2 1

13 4 3 2 1

12 1 2 3 4

11 4 3 2 1

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

18 17 18 19 20

228 13 14 15 16

18 17 18 19 20

17 100 100 100 182

16 13 3 4 4

15 1 2 3 4

14 4 3 2 1

13 4 3 2 1

12 1 2 3 4

11 4 3 2 1

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

100 100 100 100 100

228 13 14 15 16

18 17 18 19 20

17 100 100 100 182

16 13 3 4 4

15 1 2 3 4

14 4 3 2 1

13 4 3 2 1

12 1 2 3 4

11 4 3 2 1

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

228 13 14 15 16

100 100 100 100 100

18 17 18 19 20

17 100 100 100 182

16 13 3 4 4

15 1 2 3 4

14 4 3 2 1

13 4 3 2 1

12 1 2 3 4

11 4 3 2 1

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 500 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

228 13 14 15 16

100 300 100 100 100

18 17 18 19 20

17 100 100 100 182

16 13 3 4 4

15 1 2 3 4

14 4 3 2 1

13 4 3 2 1

12 1 2 3 4

11 4 3 2 1

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 300 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 1 2

228 13 214 15 16

100 100 100 100 100

18 17 18 19 20

17 100 100 100 182

16 13 3 4 4

15 1 2 3 4

14 4 3 200 1

13 4 3 2 1

12 1 2 3 4

11 4 3 2 1

10 4 5 400 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 2

4 2 2 0 0

3 5 5 3 3

2 2 3 4 5

1 1 2 100 2

228 13 14 15 16

100 100 100 100 100

18 17 18 19 20

17 100 100 100 182

16 13 3 4 4

15 1 2 3 4

14 4 3 2 1

13 4 3 2 1

12 1 2 3 400

11 4 3 2 1

10 4 5 4 2

9 10 10 10 10

8 4 3 2 1

6 1 1 1 1

7 4 3 2 1

5 0 0 2 200

4 2 2 0 0

3 5 5 3 300

2 2 3 4 5

1 1 2 1 2

228 13 14 15 16

100 100 100 100 100

Output should contain:

500

501

500

500

500

500

500

500

500

500

500

500

500

500

500

500

500

500

500

500

500

989

782

972

1251

.out and .txt are unformatted files that can be opened with most text editors. Code::Blocks can also create and read files of these types.

Specification

Homework assignments are either correct or incorrect. Do not modify any of the printf statements in the scaffold. Do not add any printf statements to the program.

Submission

Test your program for correctness. Make sure you code is easy to read and that you include a header comment and comments throughout your main function.

Finally, attach your .c source file to this assignment and submit it.

This has been asked before but the person who answered could not get the code to work. So if anyone out there who answers could you screen shot your output. I have been working a while at this seems it takes in 20 rows and 5 columns and need to find the best out of each column. So the out put will print out the best answer. Please help lost af.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!