Write the c program to accept the mXn matrix and find the largest and smallest number from the matrix using DMA

#include<stdio.h>
#include<conio.h>
void main()
{
int **ip,i=0,j=0;
int m,n,max=0,min=0;
clrscr();
printf("\n enter the m and n\n");
scanf("%d%d",&m,&n);
ip=(int**)malloc(m*sizeof(int));
for(i=0;i<m;i++)
ip[i]=(int*)malloc(n*sizeof(int));
printf("\n enter the array elements\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&ip[i][j]);
}
}
printf("\n enter array elements\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\t%d",ip[i][j]);
}
printf("\n");
}
max=ip[0][0];
min=ip[0][0];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(max<ip[i][j])
{
max=ip[i][j];
}
if(min>ip[i][j])
{
min=ip[i][j];
}
}
}
printf("\n max=%d \n min=%d",max,min);
getch();
}

No comments:

Post a Comment