Solve Sudoku using Back tracking Algorithm in C : <p>I had a feel to solve sudoku using C programming in early October, and soon I came to know its no easy task. Currently, I did write a code to do all the functioning but there seems to be an error somewhere which is preventing the desired result to get printed or even get evaluated. </p>

<p>I use the algorithm provided <a href="https://en.wikipedia.org/wiki/Sudoku_solving_algorithms" rel="nofollow noreferrer">here</a> as a reference to develop my code, </p>

<p>This is the code which I have written and correcting the error would be greatly appreciated</p>

<pre><code>#include &lt;stdio.h&gt;

int row(int i,int j,int a[9][9]);
int column(int i,int j,int a[9][9]);  //function declaration's
int grid(int i,int j,int a[9][9]);


int main()
{
    int a[9][9];
    int i,j,x;
    for (i=0;i&lt;9;i++)
    {
        for(j=0;j&lt;9;j++)
        {
            a[i][j]=0;/*for making all the array values = 0*/
            /*So that the stored garbage values will be removed*/

        }
    }
    /*Entering known elements*/
    printf("Enter the elements of known elements leaving the unknown as 0\n");
    for (i=0;i&lt;9;i++)
    {
        for(j=0;j&lt;9;j++)
        {
            scanf("%d",&amp;a[i][j]);
        }

    }

    //If a given grid is '0', lets assign a value 1 and if 1 exists in the same row or column or in ints correspond 3x3 box, increment the value upto 9

    i=0,j=0,x=1;
incr:
    if ( a[i][j] == 0)
    {
        a[i][j] = x;
        if( row(i,j,a) &amp;&amp; column(i,j,a) &amp;&amp; grid(i,j,a) )
        {
            a[i][j] = x;
        }
        else
        {
            x++;
            if ( x&gt;9)
                x = 1;
        }
    }
    else
    {
        while(i &lt; 9)
        {
            i++;
            goto incr;
        }
        if (i == 9)
        {
            i =1;
            j++;
            goto incr;
        }
        if (j == 9)
        {
            for(i=0;i&lt;9;i++)
            {
                for(j=0;j&lt;9;j++)
                {
                    printf("%d ",a[i][j]);
                }
                printf("\n");
            }
        }
    }

}

int row(int i,int j,int a[9][9])
{
    int m;
    for(m=0;m&lt;9;m++)
    {
        if( m != j)
        {
            if(a[i][j] == a[i][m])
            {
                return 0;
            }
        }
    }
    return 1;
}

int column(int i,int j, int a[9][9])
{
    int m;
    printf("%d%d",i,j);
    for(m=0;m&lt;9;m++)
    {
        if ( m != i)
        {
            if(a[i][j] == a[m][j])
            {
                return 0;
            }
        }
    }
    return 1;
}

int grid(int i,int j, int a[9][9])
{
    int m,n;

    if( i&gt;=0 &amp;&amp; i&lt;=2 &amp;&amp; j&gt;=0 &amp;&amp; j&lt;=2) /* grid 1*/
    {
        for(m=0;m&lt;=2;m++)
        {
            for(n=0;n&lt;=2;n++)
            {
                if(i != m &amp;&amp; j != n)
                {
                    if(a[i][j] == a[m][n])
                    {
                        return 0;
                    }
                }
            }
        }
        return 1;
    }
    if( i&gt;=0 &amp;&amp; i&lt;=2 &amp;&amp; j&gt;=3 &amp;&amp; j&lt;=5) /* grid 2*/
    {
        for(m=0;m&lt;=2;m++)
        {
            for(n=3;n&lt;=5;n++)
            {
                if(i != m &amp;&amp; j != n)
                {
                    if(a[i][j] == a[m][n])
                    {
                        return 0;
                    }
                }
            }
        }
        return 1;
    }
    if( i&gt;=0 &amp;&amp; i&lt;=2 &amp;&amp; j&gt;=6 &amp;&amp; j&lt;=8) /* grid 3*/
    {
        for(m=0;m&lt;=2;m++)
        {
            for(n=6;n&lt;=8;n++)
            {
                if(i != m &amp;&amp; j != n)
                {
                    if(a[i][j] == a[m][n])
                    {
                        return 0;
                    }
                }
            }
        }
        return 1;
    }
    if( i&gt;=3 &amp;&amp; i&lt;=5 &amp;&amp; j&gt;=0 &amp;&amp; j&lt;=2) /* grid 4*/
    {
        for(m=3;m&lt;=5;m++)
        {
            for(n=0;n&lt;=2;n++)
            {
                if(i != m &amp;&amp; j != n)
                {
                    if(a[i][j] == a[m][n])
                    {
                        return 0;
                    }
                }
            }
        }
        return 1;
    }
    if( i&gt;=3 &amp;&amp; i&lt;=5 &amp;&amp; j&gt;=3 &amp;&amp; j&lt;=5) /* grid 5*/
    {
        for(m=3;m&lt;=5;m++)
        {
            for(n=3;n&lt;=5;n++)
            {
                if(i != m &amp;&amp; j != n)
                {
                    if(a[i][j] == a[m][n])
                    {
                        return 0;
                    }
                }
            }
        }
        return 1;
    }
    if( i&gt;=3 &amp;&amp; i&lt;=5 &amp;&amp; j&gt;=6 &amp;&amp; j&lt;=8) /* grid 6*/
    {
        for(m=3;m&lt;=5;m++)
        {
            for(n=6;n&lt;=8;n++)
            {
                if(i != m &amp;&amp; j != n)
                {
                    if(a[i][j] == a[m][n])
                    {
                        return 0;
                    }
                }
            }
        }
        return 1;
    }
    if( i&gt;=6 &amp;&amp; i&lt;=8 &amp;&amp; j&gt;=0 &amp;&amp; j&lt;=2) /* grid 7*/
    {
        for(m=6;m&lt;=8;m++)
        {
            for(n=0;n&lt;=2;n++)
            {
                if(i != m &amp;&amp; j != n)
                {
                    if(a[i][j] == a[m][n])
                    {
                        return 0;
                    }
                }
            }
        }
        return 1;
    }
    if( i&gt;=6 &amp;&amp; i&lt;=8 &amp;&amp; j&gt;=3 &amp;&amp; j&lt;=5) /* grid 8*/
    {
        for(m=6;m&lt;=8;m++)
        {
            for(n=3;n&lt;=5;n++)
            {
                if(i != m &amp;&amp; j != n)
                {
                    if(a[i][j] == a[m][n])
                    {
                        return 0;
                    }
                }
            }
        }
        return 1;
    }
    if( i&gt;=6 &amp;&amp; i&lt;=8 &amp;&amp; j&gt;=6 &amp;&amp; j&lt;=8) /* grid 9*/
    {
        for(m=6;m&lt;=8;m++)
        {
            for(n=6;n&lt;=8;n++)
            {
                if(i != m &amp;&amp; j != n)
                {
                    if(a[i][j] == a[m][n])
                    {
                        return 0;
                    }
                }
            }
        }
        return 1;
    }
    return 0;
}
</code></pre>
