Assignment 7 - Two Dimensional Array

1.

Write a C program to return the content of the two-dimensional array as defined below.

int number[4][4] = {{0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}, {12, 13, 14, 15}};

Sample Output
Row number = 1
Column number = 2
Content = 6

Row number = 3
Column number = 4
Column number = 0
Content = 12

:

   
2. John wants to write a program to add up the numbers in two 4 x 4 tables. Numbers in cells of table 3 are formed by adding up each pair of numbers in the corresponding cells of table 1 and table 2. (Hint: two-dimensional array should be used in this program.)

Sample Output
Enter the row 0 elements of table 1: 1 2 3 4
Enter the row 1 elements of table 1: 2 3 4 5
Enter the row 2 elements of table 1: 0 0 0 0
Enter the row 3 elements of table 1: 4 5 6 7
Enter the row 0 elements of table 2: 0 1 0 1
Enter the row 1 elements of table 2: 1 0 1 0
Enter the row 2 elements of table 2: 3 4 5 6
Enter the row 3 elements of table 2: 1 1 1 1
The sum of these two tables is
1 3 3 5
3 3 5 5
3 4 5 6
5 6 7 8
   
3.

Write a C program to swap two rows or columns of characters in the two-dimensional array as defined below.

char c[4][4] = {{'a', 'b', 'c', 'd'}, {'e', 'f', 'g', 'h'}, {'i', 'j', 'k', 'l'}, {'m', 'n', 'o', 'p'}};

Sample Output
a b c d
e f g h
i j k l
m n o p

Row (1) or Col (2)? 2
Enter the column numbers: 1 3

a d c b
e h g f
i l k j
m p o n

:

   
4.

Write a program to fill up a n x n 2D array with ascending order of integers as shown below. (1 <= n <=10)

Sample output

Input size = 5
0       1       2       3       4
5       6       7       8       9
10      11      12      13      14
15      16      17      18      19      
20      21      22      23      24
   
   
5.

Write a program to fill up a n x n 2D array with ascending order of alphabet in vertical direction as shown below. (1 <= n <=5)

Sample output

Input size = 5
a       f       k       p       u
b       g       l       q       v
c       h       m       r       w
d       i       n       s       x
e       j       o       t       y
   
  Challenging Questions
 

< A minesweeper program >

There are 6 bombs embedded in this 4x4 lattice. You win if you can uncover 6 cells without being killed.

Declaration: char board[6][6];

Sample Output

1
2
3
4
1
-
-
-
-
2
-
-
-
-
3
-
-
-
-
4
-
-
-
-

Enter row number and col number: 2 3

1
2
3
4
1
-
-
-
-
2
-
-
4
-
3
-
-
-
-
4
-
-
-
-

Enter row number and col number: 4 2

1
2
3
4
1
-
-
-
-
2
-
-
4
-
3
-
-
-
-
4
-
2
-
-

Enter row number and col number: 4 1

You lose the game.

1
2
3
4
1
-
-
b
b
2
b
-
4
b
3
-
b
-
-
4
x
2
-
-
   
  Hints: how to check the total number of bombs?