Hi Fellas.
I'm in trouble to make a way to solve my sudoku,and thats is my doubt.

I need to solve this Sudoku doing in parts,like,first per section,than per row and last per column.I need to minimize the possibility of answers until i got the right answer for the index.

Code:
```#include <stdlib.h>
#include <stdio.h>

//This is for read the initial puzzle.
//The progam asks to someone digit the numbers of points that will be already revealed.
void LeTabuleiroInicial()
{
int iNumDicas;
int iIndex;
int iElemento, iValue;
int iIndexLinha,iIndexColuna;

printf("\nEnter the number of points to be disclosed:");
scanf("%d",&iNumDicas);

// Preparing the array for begin
for (iIndexLinha = 0; iIndexLinha < 81; iIndexLinha++)
{
// The possibility for each element is labeled as 9, this mean that the solution may be any digit [1-9]
iPuzzle[iIndexLinha][0]=9;
iPuzzle[iIndexLinha][10]=0;
// Declares column of each digit [1-9] as a candidate answer.
for (iIndexColuna = 1; iIndexColuna < 10; iIndexColuna++)
iPuzzle[iIndexLinha][iIndexColuna]=1;
}
//Reading of n elements revealed by the User and their sensitization  at the matrix iPuzzle
//The reading consider index of the element varying in the range [1-81] and the value ranging from [1-9].
for (iIndex = 0; iIndex < iNumDicas; iIndex++)
{
printf("Enter in sequence the index of the element and its value:");
scanf("%d %d", &iElemento, &iValue);
//Records 0 in column of all digits ,indicating that there is no answer candidate
for (iIndexColuna = 1; iIndexColuna < 10; iIndexColuna++)
iPuzzle[iElemento-1][iIndexColuna]=0;
//Records that the element has only one possible solution
iPuzzle[iElemento-1][0] = 1;
//Records the revealed solution for the element
iPuzzle[iElemento-1][10] = iValue;
//Records 1 on the colunm of respective  revealed digit
iPuzzle[iElemento-1][iValue] = 1;
}
}

void printTabuleiro()
{
int index;
int index2;

printf("\n-------------------------\n|");

for (index = 0; index<81; index++)
{
if (iPuzzle[index][0]==1)
{
for(index2 = 1; index2 <10; index2++)
{
if (iPuzzle[index][index2]==1)
{
printf(" %d", index2);
break;
}
}
}
else printf(" %c", 64 + iPuzzle[index][0] );
if ((index + 1) % 3 == 0)
printf(" |");
if (index + 1 == 81)
printf("\n-------------------------\n");
else if ((index + 1) % 27 == 0)
printf("\n-------------------------\n|");
else if ((index + 1) % 9 == 0)
printf("\n|");
}
}
int resolverSudoku()
{
int i = 1;
do
{
i++;
}
while (resolvido()!=1 && i<150);
if (i>150)
printf("Erro - Apos 150 iteracoes a solucao nao converge.");
}

int main (){

int iPuzzle[81][11];

LeTabuleiroInicial();
printTabuleiro();
resolverSudoku();
printTabuleiro();

return 0;
}```

2. Originally Posted by teuzz
You better be sorry for no indentation
You have explained what you need to do - but forgot to explain what is your problem. Do you have compilation error/warnings? Does your program run but gives incorrect result?

3. Well, I doubt you'll find anyone willing to write a sudoku solver from scratch for you.

Have a look here for strategies to solve sudoku puzzles.

Generally speaking

1) Keep track of what values are feasible for each cell.
2) For those cells where values are given reduce the set of feasible values to the one specified.
3) Repeatedly apply applicable strategies to reduce the number of feasible values in each cell, until no possible reductions occur. [These strategies are the subject of the link I gave above].
4) If no reductions are possible and any cell has more than one possible value, the puzzle is not solvable using your set of strategies. Otherwise the problem is solved.

The trick is representing the puzzle in a way so the strategies take into account groupings (i.e. rows include all numbers 1-9, as do 3x3 squares) of groups of groups (which is what some of the advanced strategies work with) - and that's where you need to spend time in designing your program. Although it's not strictly necessary, it is probably better to only apply advanced strategies if simpler strategies don't help, and only fall back on guesswork/back-tracking, etc if all other systematic strategies fail. This corresponds with most measures of puzzle difficulty and with how people often solve puzzles (a puzzle that can be solved with simple approaches is easier than a puzzle which can only be solved with the help of advanced strategies, and a puzzle where it is necessary to fall back on guesswork and backtracking are more difficult again [or deemed dirty by purists who insist that guesswork should not be needed]).