// array using dynamic allocation
#include <stdio.h>
#include<stdlib.h>
int main() {
int i, n;
int *ptr;
printf("enter the number of elements\n");
scanf("%d",&n);
ptr = (int*)malloc(n * sizeof(int));
printf("enter the array elements\n");
for ( i = 0 ; i < n ; i++)
{
scanf("%d",&ptr[i]);
}
printf("printing array elements\n");
for ( i = 0 ; i < n ; i++)
{
printf("%d\n",ptr[i]);
}
return 0;
}
0 Comments