array_practice

# array_practice - CS31 Introduction to Computer Science I...

This preview shows pages 1–2. Sign up to view the full content.

CS31: Introduction to Computer Science I Spring 2011 Copyright Brian Choi 2011. All Rights Reserved. 1 Two Dimensional Array Practice TA: Brian Choi ([email protected]) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 Consider the following code: Your job in this exercise is to replace the comment // TODO: Fill in the grid. with code that fills in grid[][] that matches the target output. For example, if the target output is: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 your code will look: for ( int i = 0; i < SIZE; i++) { for ( int j = 0; j < SIZE; j++) { grid[i][j] = i * SIZE + j + 1; } } The only requirement is that your code must work with any positive SIZE value to generate the pattern. You may use a for loop, a while loop, or a combination of several loops. You can also create whatever variables you can. Some problems may not be as easy as they seem… Have fun! 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 4 3 2 1 10 9 8 7 6 15 14 13 12 11 20 19 18 17 16 25 24 23 22 21 21 22 23 24 25 16 17 18 19 20 11 12 13 14 15 6 7 8

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern