0% found this document useful (0 votes)
30 views2 pages

Sudokuproject

c-language code for soduku

Uploaded by

Hammad Ghaffar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Sudokuproject

c-language code for soduku

Uploaded by

Hammad Ghaffar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

#include<stdio.h>
int sudoku[9][9];
void solvesudoku(int,int);
int checkrow(int row,int num)
{
int column;
for(column=0;column<9;column++)
if(sudoku[row][column]==num)
return 0 ;
return 1;
}
int checkcolumn(int column,int num)
{
int row;
for(row=0;row<9;row++)
if(sudoku[row][column]==num)
return 0;
return 1;
}
int checkgrid(int row,int column,int num)
{
row=(row/3)*3 ;
column=(column/3)*3;
int r,c;
for(r=0;r<3;r++)
for(c=0;c<3;c++)
if(sudoku[row+r][column+c]==num)
return 0;
return 1;
}
void navigate(int row,int column)
{
if(column<8)
solvesudoku(row,column+1);
else
solvesudoku(row+1,0);
}
void display()
{
int row,column;
printf("THE SOLVED SUDOKU \n");
for(row=0;row<9;row++)
{
for(column=0;column<9;column++)
printf("%d ",sudoku[row][column]);
printf("\n");
}
getch();
}
void solvesudoku(int row,int column)
{
if(row>8)
display();
if(sudoku[row][column]!=0)
navigate(row,column);
else
{
int ctr;
for(ctr=1;ctr<=9;ctr++)
{
if((checkrow(row,ctr)==1)&&(checkcolumn(column,ctr)==1)&&(checkgrid(row,column,ctr)==1))
{
sudoku[row][column]=ctr;
navigate(row,column);
}
}

67
68
69
70
71
72
73
74
75
76
77
78
79

sudoku[row][column]=0;
}
}
int main()
{
int row,column;
printf("Enter the desired sudoku and enter 0 for unknown entries\n");
for(row=0;row<9;row++)
for(column=0;column<9;column++)
scanf("%d",&sudoku[row][column]);
solvesudoku(0,0);
}

You might also like