17/* Write a ‘C’ Program to accept an mXn matrix and find the largest and smallest number from the matrix using dynamic memory allocation*/


#include<stdio.h>
#include<conio.h>
void main()
{
int **a, row,col,i,j,l,s;
clrscr();
printf(“\n Enter No of Rows and Columns:”);
scanf(“%d%d”,&row,&col);
a=(int **)malloc(row*sizeof(int*));
for(i=0;i<row;i++)
a[i]=(int *)malloc(col*sizeof(int));
printf(“\n Enter the matrix %d x %d\n”,row,col);
for(i=0;i<row;i++)
for(j=0;j<col;j++)
scanf(“%d”,&a[i][j]);
l=a[0][0];
s=a[0][0];
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
if(l<a[i][j])
l=a[i][j];
if(s>a[i][j])
s=a[i][j];
}
printf(“\n Given matrix is :- “);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
printf(“%d”,a[i][j]);
printf(“\n”);
}
printf(“\n Smallest %d”, s);
printf(“\largest %d” , l);
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s