Monday 16 March 2015

Find smallest & biggest elements of the given matrix Using C

# include <stdio.h>
# include <conio.h>

void main()
{
int mat[10][10] ;
int i, j, row, col, small, big ;
clrscr() ;
printf("Enter the order of the matrix : ") ;
scanf("%d %d", &row, &col) ;
printf("\nEnter the elements of the matrix : \n\n") ;
for(i = 0 ; i < row ; i++)
for(j = 0 ; j < col ; j++)
scanf("%d", &mat[i][j]) ;
big = mat[0][0] ;
small = mat[0][0] ;
for(i = 0 ; i < row ; i++)
{
for(j = 0 ; j < col ; j++)
{
if(mat[i][j] < small)
small = mat[i][j] ;
if(mat[i][j] > big)
big = mat[i][j] ;
}
}
printf("\nThe smallest element in the matrix is : %d\n\n",small);
printf("The biggest element in the matrix is : %d", big) ;
getch() ;
}

RUN 1 :
~~~~~~~
Enter the order of the matrix : 3 3
Enter the elements of the matrix :
4 5 6
9 7 8
1 2 3
The smallest element in the matrix is : 1
The biggest element in the matrix is : 9

No comments:

Post a Comment