Minimum element in each row of matrix

Write a program to find the minimum element in each row of the matrix.

Example:

Input:  matrix[][3]={{1,2,3},{5,4,3},{2,8,9}}
Output: Minimum of 0 row is 1
Minimum of 1 row is 3
Minimum of 2 row is 2

C Program

#include <stdio.h>
#include <limits.h>

int main()
{
    int matrix[][3] = {{123}, {543}, {289}};

    int n = 3;

    for (int i = 0i < ni++)
    {
        int minimum = INT_MAX;
        for (int j = 0j < nj++)
        {
            if (matrix[i][j] < minimum)
            {
                minimum = matrix[i][j];
            }
        }
        printf("Minimum of %d row is %d\n"iminimum);
    }
    return 0;
}


No comments:

Post a Comment