Question #338840

Write a program that creates and then reads a matrix of 5 rows and 5 columns of type int. while


reading; the program should not accept values greater than 100. For any entered value greater


than 100, the program should ask for input repeatedly. After reading all numbers, the system


should find the smallest number in the matrix and its location or index values. The program


should print the smallest number and its location (row and column) and also print their count.

Expert's answer


#include <iostream>
using namespace std;
//Implement a function for repeatedly


bool isLow100(int&num)
{
  return num<=100;
}
int main() {
  int a[5][5];
  for(int i=0;i<5;i++)
    {
      for(int j=0;j<5;j++)
        {
          cout<<"["<<i<<","<<j<<"]=";
          cin>>a[i][j];
          while(!isLow100(a[i][j]))
            {
              cout<<"["<<i<<","<<j<<"]=";
              cin>>a[i][j];
            }
        }
    }
  int mnRow=0;
  int mnCol=0;
  for(int i=0;i<5;i++)
    {
      for(int j=0;j<5;j++)
        {
          if(a[i][j]>a[mnRow][mnCol])
          {
            mnRow=i;
            mnCol=j;
          }
        }
    }
  cout<<"number Row="<<mnRow<<endl;
  cout<<"number Col="<<mnCol<<endl;
  cout<<"value="<<a[mnRow][mnCol]<<endl;
  
  return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS