Minimum element in each column of a matrix

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

Example:

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

C Program

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

int main()
{
    int matrix[][3] = {{528}, {449}, {683}};

    int n = 3;

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

    return 0;
}


No comments:

Post a Comment