Daa Assignment 7
Daa Assignment 7
N Queen’s problem
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
bool solveNQ(int N) {
int** board = (int**)malloc(N * sizeof(int*));
for (int i = 0; i < N; i++)
board[i] = (int*)malloc(N * sizeof(int));
if (solveNQUtil(board, 0, N) == false) {
printf("Solution does not exist for N = %d\n", N);
return false;
}
return true;
}
int main() {
for (int N = 4; N <= 20; N++) {
printf("N = %d:\n", N);
solveNQ(N);
xpoints =
np.array([0.000072,0.000002,0.000007,0.000002,0.000030,0.000012,0.00
0035,0.000019,0.000112,0.000051,0.001053,0.000792,0.006367,0.003528
,0.030409,0.002556,0.179589])
ypoints = np.array([4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20])
3.
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
bool solveNQ(int N) {
int** board = (int**)malloc(N * sizeof(int*));
for (int i = 0; i < N; i++)
board[i] = (int*)malloc(N * sizeof(int));
if (solveNQUtil(board, 0, N) == false) {
printf("Solution does not exist for N = %d\n", N);
free(board);
return false;
}
printSolution(board, N);
return true;
}
int main() {
for (int N = 2; N <= 3; N++) {
printf("Testing for N = %d\n", N);
solveNQ(N);
printf("\n");
}
return 0;
}
Output : -
Testing for N = 2
Solution does not exist for N = 2
Testing for N = 3
Solution does not exist for N = 3