Question: Problem statement: Place n queens on an nn chessboard so that no two queens can attack each other by being in the same row or

 Problem statement: Place n queens on an nn chessboard so that
no two queens can attack each other by being in the same

Problem statement: Place n queens on an nn chessboard so that no two queens can attack each other by being in the same row or in the same column or on the same diagonal. A sample solution for this problem is shown in the two figures below. An eight-element integer array, _ stores the rows. An array index corresponds to a column. Hence, queens[col ]= row indicates that a queen occupies cell ( row, col). The C++ program below prints the location of a Queen (row number by column number) that shares the same column as a cell given the cell number (a value 0 to 63). For example: Cell 27 is in column 3 which has a Queen on location (5 by 3 ) i.e. (row by col). The C++ program below prints the location of a Queen (row number by column number) that shares the same column as a cell given the cell number (a value 0 to 63). For example: Cell 27 is in column 3 which has a Queen on location ( 5 by 3 ) i.e. (row by col). Sample terminal output: gt+ myQueen.cpp -o queen ./queen Enter the cell number ( to 63 ): 27 Queen Located on cell 5 by 3 Complete C++ program: \#include using namespace std; int getRow(int col) \{ int queens [8]={0,4,7,5,2,6,1,3}; \} return queens [Col]; void printCell (int cell_num) \{ int col = cell_num %8; int row = getRow (col); \} cout "Queen Located on cell " row " by " col; int main() \{ int cell_number; cout "Enter the cell number (0 to 63): "; cin cell_number; printCell(cell_number); 3 I/ end main and exit Write the C++ program using RISC-V assembly instructions. Implement various functions as subroutine calls with system stack appropriately. Compile and run your program on RARS and verify that the user gets the same prompts and response as the Ct+ program. Run your program with several cell numbers (0 to 63) and verify correct outputs as shown in the figures above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!