{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

array_practice_sol

# array_practice_sol - CS31 Introduction to Computer Science...

This preview shows pages 1–3. 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 Solutions TA: Brian Choi ([email protected]) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 Problem 1 for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { grid[i][j] = j; } } Problem 2 for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { grid[i][j] = i; } } Problem 3 for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { grid[i][SIZE - j - 1] = i * SIZE + j + 1; } } Problem 4 for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { grid[SIZE - i - 1][j] = i * SIZE + j + 1; } } Problem 5 for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { grid[SIZE - i - 1][SIZE - j - 1] = i * SIZE + j + 1; } } Problem 6 for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { grid[j][i] = i * SIZE + j + 1; } }

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

View Full Document
CS31: Introduction to Computer Science I Spring 2011 Copyright Brian Choi 2011. All Rights Reserved. 2 Problem 7 for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { if (i % 2 == 0) grid[i][j] = i * SIZE + j + 1; else grid[i][SIZE - j - 1] = i * SIZE + j + 1; } } Problem 8 for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { if (i % 2 == 0) grid[j][i] = i * SIZE + j + 1; else grid[SIZE - j - 1][i] = i * SIZE + j + 1; } } Problem 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 4

array_practice_sol - CS31 Introduction to Computer Science...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online