SUDOKU

# SUDOKU - for(M=0,N=0;M<3;M,N =3 for(i=0,I=-1;i<3;i...

This preview shows pages 1–2. Sign up to view the full content.

# include <stdlib.h> # include <stdio.h> # include <conio.h> int A[9][9],a[3][3]; void StepDown(int x) { int i,j,k,I,J,K; int b[3][3]; for(I=x,i=0;I<3;I++,i++)for(J=0,j=0;J<3;J++,j++) b[I][J]=a[i][j]; for(I=0;I<x;I++,i++) for(J=0,j=0;J<3;J++,j++) b[I][J]=a[i][j]; for(i=0;i<3;i++) for(j=0;j<3;j++) a[i][j]=b[i][j]; } void main() { int i,j,k,I,J,K,M,N,P[9],r1; randomize(); clrscr(); for(i=0,k=1;i<9;k++,i++) P[i]=k; /*Randomize the values of array a 3 x 3 [LATER]*/ for(j=0;j<20;j++) for(i=0;i<9;i++) { r1=rand()%9; P[i]=(P[i]+P[r1])-(P[r1]=P[i]); } for(M=0,N=0;M<3;M++,N+=3) { for(i=0,I=0;i<3;i++) for(j=0;j<3;j++,I++) a[i][j]=P[I]; StepDown(M); for(i=0;i<3;i++) for(j=0;j<3;j++) A[i][j+N]=a[i][j];

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } for(M=0,N=0;M<3;M++,N+=3) { for(i=0,I=-1;i<3;i++) for(j=0;j<3;j++,I++) a[i][j]=P[I]; a[0][0]=P[8]; StepDown(M); for(i=0;i<3;i++) for(j=0;j<3;j++) A[i+3][j+N]=a[i][j]; } for(M=0,N=0;M<3;M++,N+=3) { for(i=0,I=-2;i<3;i++) for(j=0;j<3;j++,I++) a[i][j]=P[I]; a[0][0]=P[7];a[0][1]=P[8]; StepDown(M); for(i=0;i<3;i++) for(j=0;j<3;j++) A[i+6][j+N]=a[i][j]; } int cl=2,clr=cl; for(i=0;i<9;i++) { for(clr=cl,j=0;j<9;j++) { textcolor(clr); cprintf("%4d",A[i][j]); if((j+1)%3==0) {clr++; printf(" "); } } if((i+1)%3==0) {cl+=9; printf("\n\n");} printf("\n\n"); } getch(); }...
View Full Document

## This document was uploaded on 05/01/2011.

### Page1 / 2

SUDOKU - for(M=0,N=0;M<3;M,N =3 for(i=0,I=-1;i<3;i...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online