#include <stdio.h>
#include <stdlib.h>
int *allocate_memory(int size)
{
int *ptr = (int *)malloc(size * sizeof(int));
if (ptr == NULL)
{
printf("Failed to allocate memory.\n");
exit(1);
}
return ptr;
}
int main()
{
int n, i;
int *array;
printf("Enter the size of the array: ");
scanf("%d", &n);
array = allocate_memory(n);
for (i = 0; i < n; i++)
{
printf("Enter element %d: ", i + 1);
scanf("%d", &array[i]);
}
printf("The elements in the array are: ");
for (i = 0; i < n; i++)
{
printf("%d ", array[i]);
}
free(array);
return 0;
}