Thursday, 21 June 2012

write a c program to accept m*n matrix and find the largest and smallest number from the matrix using dynamic memory allocation


/*write a c program to accept m*n 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[10],*p,m,n,i,j,max,min,k;
clrscr();
printf("\nenter the rows and coloumn");
scanf("%d%d",&m,&n);
printf("\nenter the element:\n");
k=0;
for(i=0;i<m;i++)
{
a[i]=(int*)malloc(n * sizeof(int));
for(j=0;j<n;j++)
{
scanf("%d",a[i]+j);
*(p+k)=a[i][j];
k++;
}
}
max=*(p+0);
min=*(p+0);
for(i=0;i<k;i++)
{
if(*(p+i)>max)
max=*(p+i);
else
if(*(p+i)<min)
min=*(p+i);
}
printf("\nmaximum=%d\nminimum=%d",max,min);
getch();
}
/*
enter the rows and coloumn3 2                                                  
                                                                               
enter the element:                                                            
4 5                                                                            
7 8                                                                            
11 3                                                                          
                                                                               
maximum=11                                                                    
minimum=3                                                                      
 */

No comments: