Write a C++ searching program that declares an array matrix of type integer that prompts the user to input N n?
Write a C++ searching program that declares an array matrix of type integer that prompts the
user to input N numbers. Again prompt the user to input the number to be searched. If the
number can be found, print its position, otherwise print “ It is not in the list”.
One Response
MeanMachine
22 Sep 2009





A matrix is a two-dimensional structure, yet the only input is N, so I guess it’s N*N. With that in mind:
——————
#include <iostream>
using namespace std;
int main()
{
int A[1000][1000]; int N;
cout << "Input N:"; cin >> N;
for(int i=0; i < N; ++i)
for(int j=0; j< N; ++j)
{
cout << "[" << i << ";" << j << "] = ";
cin >> A[i][j];
}
int n;
cout << "Which number do you wish to search for?";
cin >> n;
for(int i=0; i < N; ++i)
for(int j=0; j< N; ++j)
if(A[i][j] == n)
{
cout << "Found at position [" << i << ";" << j << "] = ";
return 0;
}
cout << "Not found.";
return 0;
}