0% found this document useful (0 votes)
15 views1 page

3

The program accepts an initial number of elements from the user into an array. It then extends the array size and accepts more elements from the user, storing them in the extended array. The full array is then displayed.

Uploaded by

megeeta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

3

The program accepts an initial number of elements from the user into an array. It then extends the array size and accepts more elements from the user, storing them in the extended array. The full array is then displayed.

Uploaded by

megeeta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Write a �C� program to accept m elements from user and store those elements into an

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();
}

You might also like