TASK-
Write a C program to find greatest number in a matrix.
STEPS:
- Declare an 2D array(Matrix) either of user's entered size or any size selected by You
- Use loops to get entries of Matrix from user
- store the Value of entry [1][1] in a variable
- apply condition on the variable and the matrix if any number greater then the value of variable save this in variable
CODE:
#include<stdio.h>
int main()
{
//we are declaring matrix of order 5x5
int arr[5][5],r,c,cons;
printf("Enter entries of a 5x5 matrix: \n");
//asking for values for entries in matrix
for (r=0;r<5;r++)
{
for (c=0;c<5;c++)
{
printf("\n [%d][%d]: ",r+1,c+1);
scanf("%d",&arr[r][c]);
}
}
cons=arr[0][0]; //we have used cons where we store the value of entry [1][1]
for (r=0;r<5;r++)
{
for (c=0;c<5;c++)
{
if (arr[r][c]>cons) //here its comparing it
cons=arr[r][c];// if any greater value found, value will be saved in cons
}
}
printf("\n\nGreatest number is %d",cons);
// at last value printed!!! Task done
getchar();
return 0;
}
EXPECTED OUTPUT: