### simple algorithm to check if a Sudoku-Configuration is valid?

``````char VerifySudoku(char grid[81])
{
for (char r = 0; r < 9; ++r)
{
unsigned int bigFlags = 0;

for (char c = 0; c < 9; ++c)
{
unsigned short buffer = r/3*3+c/3;

// check horizontally
bitFlags |= 1 << (27-grid[(r<<3)+r+c])
// check vertically
|  1 << (18-grid[(c<<3)+c+r])
// check subgrids
|  1 << (9-grid[(buffer<<3)+buffer+r%3*3+c%3]);

}

if (bitFlags != 0x7ffffff)
return 0; // invalid
}

return 1; // valid
}``````
``````
``````
``````
``````
``````bool CheckSudoku(int[,] sudoku)
{
int flag = 0;

// Check rows
for(int row = 0; row < 9; row++)
{
flag = 0;
for (int col = 0; col < 9; col++)
{
// edited : check range step (see comments)
if ((sudoku[row, col] < 1)||(sudoku[row, col] > 9))
{
return false;
}

// if n-th bit is set.. but you can use a bool array for readability
if ((flag & (1 << sudoku[row, col])) != 0)
{
return false;
}

// set the n-th bit
flag |= (1 << sudoku[row, col]);
}
}

// Check columns
for(int col= 0; col < 9; col++)
{
flag = 0;
for (int row = 0; row < 9; row++)
{
if ((flag & (1 << sudoku[row, col])) != 0)
{
return false;
}
flag |= (1 << sudoku[row, col]);
}
}

// Check 3x3 boxes
for(int box= 0; box < 9; box++)
{
flag = 0;
for (int ofs = 0; ofs < 9; ofs++)
{
int col = (box % 3) * 3;
int row = ((int)(box / 3)) * 3;

if ((flag & (1 << sudoku[row, col])) != 0)
{
return false;
}
flag |= (1 << sudoku[row, col]);
}
}
return true;
}
``````

### C Questions

C Questions
C Questions

Note : All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
Programs run under DOS environment, The underlying machine is an x86 system, Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).
Predict the output or error(s) for the following:

void main()
{
int const * p=5; printf("%d",++(*p));
}
Compiler error: Cannot modify a constant value.
Explanation:
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
main()
{
char s[ ]="man"; int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
aaaa nnnn
Explanation

### Zoho Interview | Set 1 (Advanced Programming Round)

Third Round: (Advanced Programming Round) Here they asked us to create a “Railway reservation system” and gave us 4 modules. The modules were:
1. Booking
2. Availability checking
3. Cancellation
4. Prepare chart
We were asked to create the modules for representing each data first and to continue with the implementation phase.

My Solution :