Maximum element in each row of matrix

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

Example:

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

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 maximum = INT_MIN;
        for (int j = 0j < nj++)
        {
            if (matrix[i][j] > maximum)
            {
                maximum = matrix[i][j];
            }
        }
        printf("Maximum of %d row is %d\n"imaximum);
    }
    return 0;
}


No comments:

Post a Comment