diff --git a/Backtracking/N Queens.cpp b/Backtracking/N Queens.cpp new file mode 100644 index 000000000..f070c5803 --- /dev/null +++ b/Backtracking/N Queens.cpp @@ -0,0 +1,82 @@ +#include +#define N 4 +using namespace std; + +void printSolution(int board[N][N]) +{ + cout<<"\n"; + for (int i = 0; i < N; i++) + { + for (int j = 0; j < N; j++) + cout<<""<=0 && j>=0; i--, j--) + if (board[i][j]) + return false; + + /* Check lower diagonal on left side */ + for (i=row, j=col; j>=0 && i= N){ + printSolution(board); + return; + } + + /* Consider this column and try placing + this queen in all rows one by one */ + for (int i = 0; i < N; i++) + { + /* Check if queen can be placed on + board[i][col] */ + if ( isSafe(board, i, col) ) + { + /* Place this queen in board[i][col] */ +// cout<<"\n"< +using namespace std; + +Multiply(int A[][], int B[][], int n) +{ + if (n==2) + { + int p1= (a[0][0] + a[1][1])*(b[0][0]+b[1][1]); + int p2= (a[1][0]+a[1][1])*b[0][0]; + int p3= a[0][0]*(b[0][1]-b[1][1]); + int p4= a[1][1]*(b[1][0]-b[0][0]); + int p5= (a[0][0]+a[0][1])*b[1][1]; + int p6= (a[1][0]-a[0][0])*(b[0][0]+b[0][1]); + int p7= (a[0][1]-a[1][1])*(b[1][0]+b[1][1]); + + + int c[n][n]; + c[0][0]=p1+p4-p5+p7; + c[0][1]=p3+p5; + c[1][0]=p2+p4; + c[1][1]=p1-p2+p3+p6; + + return c[][]; + } + else + { + + } + +} + +int main() +{ + int p,q,r,s; + cout<<"Enter the dimensions of Matrices"; + cin>>n; + int A[n][n],; + int B[n][n],; + cout<<"Enter the elements of Matrix A"; + for (int i = 0; i < n; i++) + { + for (int j = 0; j >A[i][j]; + } + } + + + cout<<"Enter the elements of Matrix B"; + for (int i = 0; i < n; i++) + { + for (int j = 0; j >B[i][j]; + } + } + + Multiply(A, B, n); + return 0; +} \ No newline at end of file