Sudoku Source Code
Sudoku Source Code
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
const int N = 9;
return true;
}
system("cls");
cout << "\t\t\
t<==================================================
==============================>" << endl;
cout << "\t\t\t| WELCOME TO SUDOKU Game!
|" << endl;
cout << "\t\t\t| Fill in the missing numbers(represented
by 0) to solve the puzzle. |" << endl;
cout << "\t\t\
t<==================================================
==============================>" << endl;
for (int row = 0; row < N; row++){
for (int col = 0; col < N; col++){
if(col == 3 || col == 6)
cout << " | ";
cout << grid[row][col] <<" ";
}
if(row == 2 || row == 5){
cout << endl;
for(int i = 0; i<N; i++)
cout << "---";
}
cout << endl;
}
}
board[row][col] = 0;
}
}
return false;
}
return true;
}
if (solved) {
cout << "Congratulations! You have solved the puzzle." <<
endl;
printBoard(board);
}
else {
cout << "Puzzle not solved. Better luck next time." << endl;
}
int main() {
while (true) {
int choice;
cout << endl << endl;
cout << "\t\t[1] Solve the Sudoku" << endl;
cout << "\t\t[2] Unable to solve? View the solved Sudoku"
<< endl;
cout << "\t\t[3] Exit" << endl;
cout << "\t\tEnter your choice: ";
cin >> choice;
switch (choice) {
case 1:
playGame(board);
break;
case 2:
if (solveSudoku(board, 0, 0))
{
cout << "Completely Solved Sudoku is: "<< endl;
cout << endl << endl;
for (int row = 0; row < N; row++){
for (int col = 0; col < N; col++){
if(col == 3 || col == 6)
cout << " | ";
cout << board[row][col] <<" ";
}
if(row == 2 || row == 5){
cout << endl;
for(int i = 0; i<N; i++)
cout << "---";
}
cout << endl;
}
cout << endl;
cout << "Better luck next time!!!" << endl;
}
else
cout << "No solution found" << endl;
break;
case 3:
exit(0);
default:
cout << "Invalid choice" << endl;
}
return 0;
}