Friday, 22 June 2012

program to reverse an array element using dynamic memory allocation


/*program to reverse an array element using dynamic memory allocation */
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
int *p,n,i;
clrscr();
printf("\nhow many number:");
scanf("%d",&n);
p=(int*)malloc(n * sizeof(int));
printf("\nenter the element:\n");
for(i=0;i<n;i++)
scanf("%d",p+i);

printf("\nthe element in reverse order:\n");
for(i=n-1;i>=0;i--)
{
printf("%d\n",*(p+i));
}
getch();
}
/*
how many number:5

enter the element:
1 2 3 6
6

the element in reverse order:
6
6
3
2
1
*/

No comments: