SANDIP SATPATHI
510519056
1. Write a program in C to dynamically allocate space in memory for n
number
of integers where n is the input at runtime. Then find the maximum and
minimum of these numbers.
Program:
#include<stdio.h>
#include<conio.h>
#include"alloc.h"
void main()
int n,max,min,*p,i;
clrscr();
printf("Enter No. of digits:");
scanf("%d",&n);
p=(int*)calloc(n,2);//dynamic memory allocation
for(i=0;i<n;i++)
printf("Enter a number");
scanf("%d",&p[i]);
max=p[0];
min=p[0];
for(i=1;i<n;i++)
{
if(p[i]>max)
max=p[i];
if(p[i]<min)
min=p[i];
printf("Maximum=%d Minimum=%d\n",max,min);//printing output
getch();
Screenshot 1
Screenshot 2
Screenshot 3
2. Write a program in C to dynamically allocate space for an m × n
matrix where
the value of the number of rows m and number of columns n will be
taken as
input. Store the base addresses of each of the rows in another array
of pointers
where the size of the array is exactly m. Use another pointer to keep
track of
the base address of this array of pointers.
Program:
#include<stdio.h>
#include<conio.h>
#include"alloc.h"
void main()
int i,j,r,c,**a;
clrscr();
printf("Enter the number of rows:");
scanf("%d",&r);
printf("Enter the number of columns:");
scanf("%d",&c);
*a=(int**)malloc(r*sizeof(int*));//dynamic memory allocation
for(i=0;i<r;i++)
a[i]=(int*)malloc(c*2);//dynamic memory allocation
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf("Enter the number at(%d,%d):",i+1,j+1);
scanf("%d",&a[i][j]);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
printf("%4d ",a[i][j]);//printing output
printf("\n");
getch();
Screenshot 1
Screenshot 2
Screenshot 3