-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathSUDOKU-valid configuration or not.c
58 lines (55 loc) · 1.09 KB
/
SUDOKU-valid configuration or not.c
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
/*Name of the author:Bhagyashree N M
Date of modification:22/11/2021*/
//C program to SUDOKU-valid configuration or not.
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
int main()
{
int n,i,j,num;
int *arr;
printf("Enter N\n");
scanf("%d",&n);
arr=(int*)malloc(n*n*sizeof(int));
bool found=true;
printf("Enter a completed Sudoko solution\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",(arr+i*n+j));
for(i=0;i<n;i++)
{
num=*(arr+i*n+0);
for(j=i+1;j<n;j++)
{
if(num==*(arr+i*n+j))
{
found=false;
break;
}
}
if(found==false)
{
printf("no");
exit(0);
}
}
for(j=0;j<n;j++)
{
num=*(arr+j*n+0);
for(i=j+1;i<n;i++)
{
if(num==*(arr+j*n+i))
{
found=false;
break;
}
}
if(found==false)
{
printf("no");
exit(0);
}
}
printf("yes");
return 0;
}