i was trying to make a sudoku solver using c..since i hav just started learning c, i dont know anything about pointers and functions..
so i am trying to make it using simple loops and array..(is it actually possible to make it without functions??)
i have written a code for it(its not complete yet) ..when i compile the program ,it shows no error..but when i run it,
no output is coming..the program goes as:
Code:
#include<stdio.h>
#include<conio.h>

void main()
{
 int a[10][10],i,j,k,b,l,ans;
 clrscr();
 for(i=1;i<10;i++)              
 {
  for(j=1;j<10;j++)
  {
   printf("a(%d,%d)\t",i,j);
  }
  printf("\n\n\n");
 }
 for(i=1;i<10;i++)                     // input from user
 {
  for(j=1;j<10;j++)
  {
   printf(" a[%d,%d]?\n",i,j);         // i hav used 0 to represent a blank box
   scanf("%d",&a[i][j]);
  }
 }
 for(i=1;i<10;i++)                     //
 {
  for(j=1;j<10;j++)
  {
   b=0;
   if(a[i][j]==0)                      //checks whether the box is empty
   {
    end:
    ans=0;
    b=b+1;                             //gives a value to empty box
    for(k=1;k<10;k++)
    {
     if(a[i][k]==b||a[k][j]==b)        //checks whether that value is already occupied in the same row and column
     {
      ans=1;
     }
    }
    for(k=1;k<4;k++)                   //
    { 
     for(l=1;l<4;l++)
     {
      if(a[3*(i/3)+l][3*(j/3)+k]==b)   //checks whether that value is occupied by the bigger box containing nine boxes
      {
       ans=1;
      }
     }
    } 
    if(ans=1)
    {
     goto end;                         //if yes, than it goes back and assign a higher value to the box 
    }
    a[i][j]=b;
   }  
  }   
}
 for(i=1;i<10;i++)                     //prints the result
 {
  for(j=1;j<10;j++)
  {
   printf("%d\t",a[i][j]);
  }
  printf("\n");
 }
getch();
}
the program is not yet complete as i havnt introduced the feedback yet..
can u tell me what is the problem with the code so far??why is it not giving any output??
when i remove the part which checks 'if the value lies in bigger box' it works fine..why??


srry i am not gud at explaining but hope u hav understood..

Last edited by shabbir; 10Jul2008 at 09:39.. Reason: Code block