Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need a help with correctiong my code: (c - programming) I have a soduko board I want to go over every row and every

I need a help with correctiong my code: (c - programming) I have a soduko board I want to go over every row and every column and check if there is a number that appears more than once

#include #include #include

#define MAX4USED 10

int n; //size of the sodoku board

bool CheckAppearingInRow(int matrix [n][n]) { int used[MAX4USED] = {0}; int index = 1; int row = 0; while (index <= n) { for(int j = 0; j < n; j++) { if(matrix[row][j] == index ) { used[index] +=1; } } for(int i = 0; i <= n ; i++) { if (used[i] > 1) { return true; } used[i] = 0; } index += 1; } row += 1; while (row < n) { CheckAppearingInRow(matrix); } return false; }

bool CheckAppearingInColumn(int matrix [n][n]) { int used[MAX4USED] = {0}; int index = 1; int col = 0; while (index <= n) { for(int i = 0; i < n; i++) { if(matrix[i][col] == index ) { used[index] +=1; } } for(int i = 0; i <= n ; i++) { if (used[i] > 1) { return true; } used[i] = 0; } index += 1; } col += 1; while(col < n){ CheckAppearingInColumn(matrix); } return false; }

int main() { printf("Please enter your sodoku dimension:"); scanf("%d", &n); int a[n][n]; printf(" Insert your sodoku board "); printf("Instruction: Enter 0 for blank "); for(int i=0; i for(int j=0; j scanf("%d", &a[i][j]); } } if (CheckAppearingInRow(a)== true || CheckAppearingInColumn(a) == true ) { printf(" No solution! "); } return 0; }

i use this matrix for test (this is a matrix with solution so I change numbers in rows or columns) for row 0 it works for every number, in other rows it doesn't work for coumns it doesn't work also

7 1 0 0 0 0 6 0 9 2 0 0 0 0 3 0 0 0 0 0 0 1 5 0 0 0 8 0 0 7 0 0 0 0 9 0 0 0 6 0 0 0 7 0 0 0 2 0 0 0 0 4 0 0 1 0 0 0 2 9 0 0 0 0 0 0 3 0 0 0 0 4 9 0 5 0 0 0 0 8 6 *Please run the code for more than one test before sending me! 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions