Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

Program to Display the Largest Element of each row in a 2-D Array

C Program to Display the Maximum Element of each row in a 2-D Matrix

  • In this problem, we are required to implement a program wherein we have to display the largest element in each row in a 2-D array.
  • First, we take a 2-Darray as an input from the user.
  • After that we compare each element of the array in a row to determine the largest element in each row and display it as output.
#include<stdio.h>
int main ()
{
int i, j, r, c, n, a[100][100], max[100];
printf ("Enter the number of rows: ");
scanf ("%d", &r);
printf ("Enter the number of columns: ");
scanf ("%d", &c);
printf ("Enter the elements of the array- \n");

for (i = 0; i < r; i = i + 1)
{
for (j = 0; j < c; j = j + 1)
{
printf("[%d %d]: ", i + 1, j + 1);
scanf("%d", &a[i][j]);
}
}

printf ("The input matrix is:- \n");
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
printf ("%d\t", a[i][j]);
}
printf ("\n");
}

for (i = 0; i < r; i++)
{
max[i] = a[i][j];
for (j = 0; j < c; j++)
{
if (a[i][j] > max[i])
{
max[i] = a[i][j];
}
}
}

for (i = 0; i < r; i++)
{
printf ("Maximum element of the row %d is: %d\n", i, max[i]);
}
return 0;
}
Disclaimer-: The questions provided on this page are only model practice questions there is no surety that these questions have been previously asked in any company placement papers, these questions here only have the sole purpose to make you practice coding questions