Program 4 :
Write a function void fillRandom(int A[ ][COL], int num_rows, int num_cols) that fills
the array A with the random numbers between -3 and 3 (including -3 and 3). Write a function int
numNonZero(int A[][COL], int num_rows, int num_cols) that finds and returns the amount of non-zero elements of
the array A. Write a program that performs the following:
- Declares TWO two-dimensional arrays of integers of size 4X4 each (4 rows and 4 columns)
- Fills EACH array with the random generated numbers between -3 and 3 using function
fillRandom
- Prints EACH random array using function void printArray(int A[ ][COL], int num_rows, int
num_cols)
- Calculates the number of non-zero elements in each array and prints results
with an appropriate message.
- Finds array with the maximal amount of non-zero elements
Team Work
Mini-Sudoku
To solve a Mini-Sudoku puzzle, one must fill in a 4X4 grid with the
integers from 1 to 4 in such a way that each integer appears once in each
row, once in each column, and once in each 2X2 subgrid. (Normally Sudoku
is played on a 9X9 grid). For example, the following would be a solution.
1 2 3 4
3 4 1 2
2 1 4 3
4 3 2 1
Write a program which takes four rows of four integers as input. If the
grid represents a
legitimate solution, your program should print the words .Valid Solution.;
otherwise, it should print one or more of the following, depending on
which criteria fail:
- Invalid row
- Invalid column
- Invalid subgrid
Your program should display each reasons which is responsible for a
failure on a separate
line, but the same reason should not be given more than once. For example,
it might print
both 'Invalid row' and 'Invalid subgrid' if both of these reasons apply,
but it should print
'Invalid row' only once, regardless of how many rows actually fail.
You may assume the input consists only of integers from 1 to 4, and that
there are exactly four rows, each with four integers.
Use two dimensional array to solve this problem
Here are some sample inputs, along with the corresponding output.
Input
1 2 3 4
3 4 1 2
2 1 4 3
4 3 2 1
Output: VALID
Input
1 2 3 4
4 3 2 1
1 2 3 4
4 3 2 1
Output: Invalid column
Input
2 2 2 2
1 1 1 1
3 3 3 3
4 4 4 4
Output: Invalid row, Invalid subgrid
Input
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output: Invalid row, Invalid column,
Invalid subgrid