Question #37983

a) Find the minimum number and maximum number for each row. in 2D array
1

Expert's answer

2013-12-25T11:31:10-0500

Answer on Question#37983, Programming, C++


#include <iostream>
using namespace std;
int main()
{
    int arr[5][4] =
    {
        {1,2,3,4},
        {2,3,4,5},
        {3,4,5,6},
        {4,5,6,7},
        {5,6,7,8}
    };
    for(int i = 0; i < 5; i++)
    {
        int min = arr[i][0];
        int max = arr[i][0];
        for(int j = 0; j < 4; j++)
        {
            if(min > arr[i][j])
            {
                min = arr[i][j];
            }
            if(max < arr[i][j])
            {
                max = arr[i][j];
            }
        }
        cout << "Row: "<< i + 1 <<" Max: " << max << " Min: "<<min << 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!
LATEST TUTORIALS
APPROVED BY CLIENTS