Thank you for helping!!!!1
Thank you for helping!!!!1
So where is YOUR effort?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
There are more elegant ways to do this, but take a look at this basic idea:
This tests one digit which you are trying out, to see if it can work in the box of 9. In this version, I used rows and columns 1 through 9, instead of 0 through 8, so you may need to adjust.Code:int TestBox(int nudigit, int r, int c) { //just tests one box int c1, r1, i, n, lowrow, lowcol; /*get lowrow & lowcol*/ switch (r) { case 1: case 2: case 3: lowrow = 1; break; case 4: case 5: case 6: lowrow = 4; break; case 7: case 8: case 9: lowrow = 7; break; } if(c < 4) lowcol = 1; else if(c > 3 && c < 7) lowcol = 4; else lowcol = 7; for(r1 = lowrow; r1 < lowrow + 3; r1++) { for(c1 = lowcol; c1 < lowcol + 3; c1++) { if(nudigit == A[r1][c1]) return 0; } } return 1;
here is my effort from line 36 to 57
Code:1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 int t,count=1,i,j,k=0,n,z,l=0,p,f=0,key=0; 6 int a[100][100]; 7 scanf("%d",&t); 8 for(count=1;count<=t;count++) 9 { 10 scanf("%d",&n); 11 for(i=0;i<n;i++) 12 for(j=0;j<n;j++) 13 scanf("%d",&a[i][j]); 14 for(i=0;i<n;i++) 15 { 16 z=0; 17 for(j=0;j<n;j++) 18 z=z+a[i][j]; 19 if(z==(n*(n+1))/2) 20 k=1; 21 else 22 k=0; 23 } 24 for(j=0;j<n;j++) 25 { 26 z=0; 27 for(i=0;i<n;i++) 28 z=z+a[i][j]; 29 if(z==(n*(n+1))/2) 30 l=1; 31 else 32 l=0; 33 } 34 z=sqrt(n); 35 u=0;v=0; 36 for(i=u;i<u+z&&i<n;i++) 37 { 38 for(j=v;j<v+z&&j<n;j++) 39 { 40 printf("%d",a[i][j]); 41 z=z+a[i][j]; 42 f++; 43 } 44 if( 45 if(i==u+z-1&&j==v+z-1) 46 v=v+z; 47 printf("\n"); 48 if(f==n) 49 { 50 f=0; 51 if(z==(n*(n+1))/2) 52 p=1; 53 else 54 p=0; 55 z=0; 56 } 57 } 58 if(k==1&&l==1&&p==1) 59 printf("YES\n"); 60 else if(k!=1||l!=1||p!=1) 61 printf("NO\n"); 62 } 63 return 0; 64 }
How about removing the extra set of line numbers?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
my code is not complete....please help me
I m a beginner.
Why is your Sudoku array so HUGE? Are you trying to work with Super sized Sudoku puzzles?
You'll find it easier to develop your program using the standard 9x9 grid, and then move to the larger puzzle size. Definitely, you should be setting this up with separate functions!
And add some notes to your code! Your variable names are not helping.
Last edited by Adak; 09-25-2012 at 02:59 PM.