3)Write a C program to accept m element from the user and store those element into an array.Extend the size of an element to accept to n from user and store that element into an array display the complete array.


#include<stdio.h>
#include<conio.h>
void main()
{
int size,i,newsize,*p;
clrscr();
printf(“\n\nENTER THE SIZE FOR AN ARRAY \n\n”);
scanf(“%d”,&size);
p=(int *)malloc(size*sizeof(int));
printf(“\n\nENTER THE ELEMENT”);
for(i=0;i<size;i++)
{
scanf(“%d”,&p[i]);
}
printf(“\n\nENTER ELEMENTS ARE \n\n”);
for(i=0;i<size;i++)
{
printf(“%d\t”,p[i]);
}
printf(“\n\nENTER THE NEW SIZE FOR AN ARRAY”);
scanf(“%d”,&newsize);
p=(int *)realloc(p,newsize);
printf(“\n\nELEMENTS AT NEW SIZE ARE\n”);
for(i=0;i<newsize;i++)
{
printf(“%d\t”,p[i]);
}
printf(“\n\nENTER THE ELEMENTS FOR NEW SIZE”);
for(i=size;i<newsize;i++)
{
scanf(“%d”,&p[i]);
}
printf(“\n\nALL THE ELEMENTS OF AN ARRAY\n\n”);
for(i=0;i<newsize;i++)
{
printf(“%d\t”,p[i]);
}
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s