Tuesday 10 January 2012

C program to find the largest and smallest values of a matrix



#include<stdio.h>
main()
{
int a[10][10],l,s,i,j,p,q;
printf("Enter the order of the matrix\n");
scanf("%d%d",&p,&q);
printf("Enter the values\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
scanf("%d",&a[i][j]);
}
l=a[0][0];
s=a[0][0];
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
if(l<a[i][j])
l=a[i][j];
if(a[i][j]<s)
s=a[i][j];
}
}
printf("The matrix is\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("The biggest value = %d\n",l);
printf("The smallest value = %d\n",s);
}



You Like It!? Then kindly share with your Friends.
Comments
0 Comments

No comments:

Post a Comment