Answer to Question #338840 in C++ for Ashir

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.

1
Expert's answer
2022-05-09T14:55:14-0400


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS