Underlying concept to demonstrate: Mixed allocation of 2-d array (static and dynamic)
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p[30];
int i,j,max,min,row,col;
printf("\n Enter the no. of rows of matrix:");
scanf("%d",&row);
printf("\n Enter the no. of coloumns of matrix:");
scanf("%d",&col);
for(i=0;i<row;i++)
{
p[i]=(int*)malloc(col*sizeof(int));
}
printf("\n Enter the elements of matrix:\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("p[%d][%d]:",i,j);
scanf("%d",&p[i][j]);
}
}
max=p[0][0];
min=p[0][0];
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(p[i][j]>max)
max=p[i][j];
if(p[i][j]<min)
min=p[i][j];
}
}
printf("\n Maximum value =%d and minimum =%d",max,min);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p[30];
int i,j,max,min,row,col;
printf("\n Enter the no. of rows of matrix:");
scanf("%d",&row);
printf("\n Enter the no. of coloumns of matrix:");
scanf("%d",&col);
for(i=0;i<row;i++)
{
p[i]=(int*)malloc(col*sizeof(int));
}
printf("\n Enter the elements of matrix:\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("p[%d][%d]:",i,j);
scanf("%d",&p[i][j]);
}
}
max=p[0][0];
min=p[0][0];
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(p[i][j]>max)
max=p[i][j];
if(p[i][j]<min)
min=p[i][j];
}
}
printf("\n Maximum value =%d and minimum =%d",max,min);
return 0;
}





0 comments