How to Write a C program to reverse an array elements using Dynamic Memory Allocation in C Programming Language ?
/*c program to reverse an array elements using Dynamic Memory Allocation*/
#include<stdio.h>
#include<conio.h>
void main()
{
int *ip,n,i;
int max=0;
clrscr();
printf("\nEnter the limit: ");
scanf("%d",&n);
ip=(int*)malloc(n*sizeof(int));
printf("\nEnter the elements:\n");
for(i=0;i<n;i++)
{
scanf("%d",&ip[i]);
}
printf("\nEntered elements are:\n");
for(i=0;i<n;i++)
{
printf("\n%d",ip[i]);
printf("\n");
}
printf("\nReverse array is:");
for(i=n-1;i>=0;i--)
{
printf("\n%d",ip[i]);
}
getch();
}
OUTPUT:
Enter the limit: 4
Enter the elements:
1
2
3
4
Entered elements are:1 2 3 4