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 user and store that elements into an array and display the complete array.(use malloc() and realloc() functions.


#include

#include

void main()

{

int *p,n,m,i;

clrscr();

printf("\n Enter The Size:");

scanf("%d",&n);

p=(int*)malloc(n*sizeof(int));

printf("\n Enter %d Numbers\n",n);

for(i=0;i<n;i++)

{

scanf("%d",&p[i]);

}

printf("\n ENTERED NUMBERS ARE: ");

for(i=0;i<n;i++)

{

printf("\t%d",p[i]);

}




printf("\n Enter New Size:");

scanf("%d",&m);

p=realloc(p,m);

printf("\n Enter Elements For Newsize:\n");

for(i=n;i<m;i++)

{

scanf("%d",&p[i]);

}

printf("\n New Numbers Entered are: ");

for(i=n;i<m;i++)

{

printf("\t%d",p[i]);

}

printf("\n All Elements of an Array are: ");

for(i=0;i<m;i++)

{

printf("\t%d",p[i]);

}

getch();

}


/*OUTPUT


 Enter The Size:4


 Enter 4 Numbers

1

4

2

3


 ENTERED NUMBERS ARE:   1       4       2       3

 Enter New Size:6


 Enter Elements For Newsize:

2

8


 New Numbers Entered are:       2       8

 All Elements of an Array are:  1       4       2       3       2       8 */
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 user and store that elements into an array and display the complete array.(use malloc() and realloc() functions. 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 user and store that elements into an array and display the complete array.(use malloc() and realloc() functions. Reviewed by on November 16, 2013 Rating: 5
Powered by Blogger.