/*Check whether the given filled sudoku puzzle is correct or not */
#include<stdio.h>
#include<conio.h>
void main()
{
int a[9][9],sum1,sum2,flag=0,i,j; printf("Enter the elements of sudoku Row wise\n");
for(i=0;i<9;i++)
for(j=0;j<9;j++)
scanf("%d",&a[i][j]);
for(i=0;i<9;i++)
{
sum1=0;
sum2=0;
for(j=0;j<9;j++)
{
sum1+=a[i][j];
sum2+=a[j][i];
}
if(sum1!=45 || sum2!=45)
{
flag=1;
break;
}
}
for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
printf(" %d ",a[i][j]);
printf("\n\n");
}
if(flag==1)
printf("\n----THE PUZZLE IS WRONG---\n"); else
printf("\n----THE PUZZLE IS RIGHT---");
}
No comments:
Post a Comment