CS 223 Multi-D Array in Class Exercise

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

CS 223 In Class Exercise – arrays and multi-

dimensional arrays
Single dimensional array
1. Declare a 16-integer array ilist and assign 1, 2, and 3 to the first three elements.

2. Given ilist declared in question 1, write a statement to assign the forth element (at index 3) with
the sum of first three elements in ilist, (index at 0, 1, 2)

3. Declare a 32-char array name and assign string “Hello” as its initialization value.

4. Given name declared in question 3, write a statement to print out the string content in name.

printf(“ “, );

2D array
5. Declare an 2D 2×8 integer array iMatrix and initialize all elements with 0.

6. Use iMatrix declared in question 5, write a statement to set the element at row 0 and column
7 in iMatrix to 100.

7. Declare 2D 4×8 char array strlist and use following strings to initialize rows: “abc”, “def”,
“ghi”, and “jkl”.
8. Given strlist declared in question 7, write a statement to print out the content in row 2 (the 3rd
row) of strlist.

printf(“%s”, );
--------------------------------------------

3D array
9. Declare 3D 9×9×9 integer array cube and initialize all elements with 0.

10. Given cube declared in question 9, write a statement to set the center of 3D cube to 1.

You might also like