In this assignment you will write a small C program produce

In this assignment you will write a small C program. produce the specified output. C program. Your program should compile conrectl hould compile correctly and Please note that the computer program should comply with the commenting and formatting rules as has been done in class. For example, there should be a header for the whole program that gives the author\'s name, class name, date, and description. End braces should be commented, and there are alignment and indenting requirements as discussed. Please ask if you have any questions Program #1 In this program, you will use a function to validate iif. a) (30 points) A given one dimensional array of size-9, all the numbers from 1 to 9 appear exactly once. b) (40 points) A given two dimensional array of size 3x3, all the numbers from 1 to 9 appear exactly once c) (30 points) A given two dimensional array of size 3x9, a. b. On every row, all the numbers from 1 to 9 appear exactly once E very square 3x3, all the numbers from 1 to 9 appear exactly once The functions should receive/retun for 1) Case a) receives: an array of integers and the array size. Returns 1 if the numbers from 1 2) Case b) receives: an array of integers, an integer for the number of rows and an integer 3) Case c) receives: an array of integers, an integer for the number of rows and an integer to 9 appear only once, 0 otherwise. for the number of columns. Returns 1 if the numbers from 1 to 9 appear only once, 0 otherwise for the number of columns. Returns 1 if the numbers from 1 to 9 appear only once on each row, 2 if the numbers 1 to 9 appear on each of the 3x3 squares and 3 if both conditions (rows and squares) are true. To test your code, you can hardcode and use the following(you can create your own too): 1) Case a) ={4\' 5, 2, 3,9,7,1,6,8); ={3,9,7,I, 6, 8, 4, 5, 2); {1, 6, 8, 4, 6, 2, 3,9,7);

Solution

Here is the code for you:

#include <stdio.h>
int isFound(int array[], int size, int num)
{
for(int i = 0; i < size; i++)
if(array[i] == num)
return 1;
return 0;
}
int uniqueValues(int array[], int size)
{
for(int i = 0; i < size; i++)
if(!isFound(array, size, i+1))
return 0;
return 1;
}

int uniqueValues3x3(int array[][10], int rows, int columns)
{
for(int i = 0; i < rows; i++)
for(int j = 0; j < columns; j++)
if(!isFound(array[i], columns, i*rows + (j+1)))
return 0;
return 1;   
}
int uniqueValues3x9(int array[][10], int rows, int columns)
{
int firstCheck = 1;
for(int i = 0; i < rows; i++)
if(!uniqueValues(array[i], columns))
firstCheck = 0;
int temp[10][10];
int secondCheck = 1;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
for(int k = 0; k < 3; k++)
temp[j][k] = array[j][i*3+k];
if(!uniqueValues3x3(temp, 3, 3))
secondCheck = 0;
}
if(firstCheck && secondCheck)
return 3;
else if(firstCheck)
return 1;
else if(secondCheck)
return 2;
return 0;
}
int main()
{
int test1[] = {4, 5, 2, 3, 9, 7, 1, 6, 8};
int test2[] = {3, 9, 7, 1, 6, 8, 4, 5, 2};
int test3[] = {1, 6, 8, 4, 6, 2, 3, 9, 7};
printf(\"%i\ \", uniqueValues(test1, 9));
printf(\"%i\ \", uniqueValues(test2, 9));
printf(\"%i\ \", uniqueValues(test3, 9));
}

If you need any refinements, just get back to me.

 In this assignment you will write a small C program. produce the specified output. C program. Your program should compile conrectl hould compile correctly and
 In this assignment you will write a small C program. produce the specified output. C program. Your program should compile conrectl hould compile correctly and

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site