8. Program to find Maximum and Minimum elements in a matrix
SOURCE CODE :
#include<stdio.h>
#include<time.h>
int main()
{
clock_t start,end;
double ctu;
int m,n,c,d,max,min,a[50][50];
clrscr();
start=clock();
printf("\n Enter the number of row and colums: ");
scanf("%d%d",&m,&n);
printf("\n Enter the elements: ");
for(c=0;c<m;c++)
for (d=0;d<n;d++)
scanf("%d",&a[c][d]);
min=a[0][0];
for(c=0;c<m;c++)
for(d=0;d<n;d++)
if (a[c][d]<min)
min=a[c][d];
printf("\n Minimum element in the matrix is %d\n",min);
max=a[0][0];
for(c=0;c<m;c++)
for(d=0;d<n;d++)
if (a[c][d]>max)
max=a[c][d];
printf("\n Maximum element in the matrix is %d\n",max);
end=clock();
ctu=((double)(end-start))/CLOCKS_PER_SEC;
printf("\n Time used %f sec",ctu);
getch();
return 0;
}
OUTPUT :
No comments:
Post a Comment