How the sudoku algorithm works

The short answer: The program tries all possible values for each cell, and the combination which obeys all sudoku's rule is displayed as the solution.

The long answer:

Recursive Functions

Recursive functions are functions that call themselves in their function body. Basically:

void func(){

    //do something

    func();    //function calling itself


It doesn't take a genius to realize the above piece of code would result in an infinite loop (Not a genius? Just nod your head). However, with an appropriate check, recursive functions can actually be useful.

long factorial(int n){

    if (n == 0)

        return 1;


        return (n * factorial(n-1));