Question: Page 43, Problem #2- Rewrite the code so that it works properly. You can not use go to . Your program should query the user

Page 43, Problem #2- Rewrite the code so that it works properly. You can not use go to. Your program should query the user for the value to be searched for. You can either hard wire data into the n x n matrix or permit the user to fill the matrix interactively. Remember that a matrix is a static structure; it is not acceptable to set the size of the matrix at run-time; it must be fixed at compile-time. The use of break to exit a loop or a function should be avoided (and will be penalized).

Code from text follows:

/* Search the entries of the n x n matrix mat in rowise order for an entry equal to item*/

bool found;

for (int row=0; row

for (int col=0; col

if (mat[row][col]==item)

found=true;

else

found=false;

if (found)

cout<<"item found ";

else

cout<<"item not found "

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!