Debugging and re-coding
Alright I am suppose to design a program to search a square nxn matrix for
a target value. I need to include in it a means of specifying the size of
the matrix and filling the data (either hardwire it in or allowing the
user to populate it), and allowing the user to enter the target value.
This is how far I have gotten. I do not know if it is working properly
because my answer is always item found. any suggestions?
/* Search the entries of the n X n matrix mat in rowwise order for an
entry to item */
#include <iostream>
using namespace std;
int main(void)
{
int n=10, item, row=15, col=20, mat[row][col];
bool found;
cout << "Enter a poistive integer you want to be searched: ";
cin >> item;
if (mat[row][col]==item)
found = true;
else
found = false;
if(found==true)
cout << "item found" ;
else
cout << "item found ";
return 0;
}
No comments:
Post a Comment