SUDOKU - } for(M=0,N=0;M<3;M++,N+=3) {...

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

View Full Document Right Arrow Icon
# 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];
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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&lt;3;M++,N+=3) { for(i=0,I=-1;i&lt;3;i++) for(j=0;j&lt;3;j++,I++) a[i][j]=P[I]; a[0][0]=P[8]; StepDown(M); for(i=0;i&lt;3;i++) for(j=0;j&lt;3;j++) A[i+3][j+N]=a[i][j]; } for(M=0,N=0;M&lt;3;M++,N+=3) { for(i=0,I=-2;i&lt;3;i++) for(j=0;j&lt;3;j++,I++) a[i][j]=P[I]; a[0][0]=P[7];a[0][1]=P[8]; StepDown(M); for(i=0;i&lt;3;i++) for(j=0;j&lt;3;j++) A[i+6][j+N]=a[i][j]; } int cl=2,clr=cl; for(i=0;i&lt;9;i++) { for(clr=cl,j=0;j&lt;9;j++) { textcolor(clr); cprintf(&quot;%4d&quot;,A[i][j]); if((j+1)%3==0) {clr++; printf(&quot; &quot;); } } if((i+1)%3==0) {cl+=9; printf(&quot;\n\n&quot;);} printf(&quot;\n\n&quot;); } getch(); }...
View Full Document

Page1 / 2

SUDOKU - } for(M=0,N=0;M&amp;amp;lt;3;M++,N+=3) {...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online