In this tutorial you will learn about the C Program to find Largest Element in Matrix and its application with practical example.
C Program to Find Largest Element in Matrix
In this tutorial, we will learn to create a C program that will find the Largest Element in Matrix using C programming.
Prerequisites
Before starting with the tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop in C programming.
- Conditional statement in C programming.
Program to find Largest Element in Matrix
In c programming, it is possible to take a numerical input for the size of the matrix and the elements of the matrix from the user and find the Largest Element in Matrix with the help of a very small amount of code. The C language has many types of header libraries which has supported function in them with the help of these files the programming is easy.
Algorithm:-
With the help of this program, we can find the Largest Element in Matrix.
1 2 3 4 5 6 7 8 9 |
1. Declaring the variables for the program. 2. Taking the input elements of matrix. 3. Calculating the largest elements of matrix. 4. Printing the calculated elements. 5. End Program. |
Program:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* C Program to find Largest Element in Matrix */ #include<stdio.h> int main() { /* declaring the variable local for the program */ int mat[3][3], i, j, max; /* taking in put from the user in the form of matrix 3*3 */ printf("Enter any 3*3 matrix: "); /* Reading the matrix from the user with the help of for loop */ for(i=0; i<3; i++) { for(j=0; j<3; j++) scanf("%d", &mat[i][j]); } /* Finding the largest element in the matrix with the help of loop */ max = mat[0][0]; for(i=0; i<3; i++) { for(j=0; j<3; j++) { if(max<mat[i][j]) max = mat[i][j]; } } /* Printing the output largest number from the matrix */ printf("\nLargest Element = %d", max); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- mat[3][3]= it will hold the integer value.
- i= it will hold the integer value.
- j= it will hold the integer value.
Taking the elements of the matrix from the user.
Calculating the largest element matrix.
Printing the largest element of the matrix.