3
3
array. Extend the size of an array to n, accept n-m elements from the user and
store that elements into an array and display the complete array. (use malloc() and
realloc() function)
#include<stdio.h>
#include<conio.h>
void main()
{
int n,m,i;
int *a,*b;
printf("\nenter size of:");
scanf("%d",&n);
a=(int *)malloc(n*sizeof(int));
printf("\nenter %d elements:",n);
for(i=0;i<n;i++)
{
scanf("%d",a+i);
}
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
printf("\nenter size of m:");
scanf("%d",&m);
b=(int *)realloc(a,m*sizeof(int));
printf("\nenter %d elements:",m);
for(i=0;i<m;i++)
{
scanf("%d",b+i);
}
for(i=0;i<m;i++)
{
printf("%d\t",b[i]);
}
getch();
}