#include <stdio.h>
int main()
{
int n,i,*ptr,sum=0;
printf("Enter number of elements: ");
scanf("%d",&n);
ptr=(int*)malloc(n*sizeof(int));
if(ptr==NULL)
{
printf("Error! memory not allocated.");
return 0;
}
printf("Enter elements of array: \n");
for(i=0;i<n;++i)
{
scanf("%d",ptr+i);
sum+=*(ptr+i);
}
printf("Elements of array are :\n");
for(i = 0;i<n; i++)
{
printf("%d ",ptr[i]);
}
free(ptr);
return 0;
}
OUTPUT
Enter number of elements: 5
Enter elements of array:
4
8
6
2
1
Elements of array are :
4 8 6 2 1