*********** Q2 ****************************************************** function M = transposeNegative(M) % A pair across the main diagonal have indices (i,j) and (j,i). % This solution moves thorough all rows and columns BELOW THE MAIN % DIAGONAL, at each position check the cell in the transposed % position and swap if both cells are negative. % Grading note: no new matrix for row = 2:length(M) for col=1:row-1 if (M(row,col)<0 & M(col,row)<0) %entries (i,j)&(j,i) <0 tmp = M(row,col); M(row,col) = M(col,row); M(col,row) = tmp; end end end *********** Q3 ****************************************************** % Prompt the user input nsteps = input('Enter number of steps: '); % generate starting coordinates : integer between -10 and 10 star_coord = floor(21*rand(1,2))-10; x = star_coord(1); y = star_coord(2); for i=1:nsteps step_rand = floor(rand*4) % random integer number between 0-3 if (step_rand == 0) % +1 in x direction x = x+1; elseif (step_rand == 1) % -1 in x direction x = x-1; elseif (step_rand == 2) % +1 in y direction y = y+1; elseif (step_rand == 3) % -1 in y direction y = y-1; end fprintf('Location after step %d: x=%d, y=%d\n',i,x,y); end *********** Q4 ****************************************************** int n = Keyboard.readInt(); // size of square int col, row = 1; // column,row number while ( row <= n ) { col = 1; while ( col <= n ) { if ( row==1 || row==n || col==1 || col==n || row==col ) System.out.print("*"); else System.out.print(" "); col++; } System.out.println(); row++; } *********** Q5 ****************************************************** public class Seesaw { public static void main(String[] args) { final int MAXCYCLES = 25; Person p1 = new Person(); Person p2 = new Person(); int cycles = 0; // no. of cycles so far while ( !p1.wannaStop() && !p2.wannaStop() && cycles