[Solved] C I need to use malloc and a dynamically allocated array however I need to print the user input


issue 1: you are allocating sizeof(double) to store int
issue 2: You are not traversing array to print numbers

int main(void)
{
  int user_input = 0, elements = 0;
  printf("How many int elements will you enter?\n");
  scanf("%d", &elements);

  int* dynamic_array = (int *)malloc(sizeof(int)* elements);
  if(dynamic_array == NULL) {
     perror(" Out of memory ");
     return 0;
  }

  for (int i = 0; i < elements; i++)
  {
    printf("Element %d?\n", i + 1);
    scanf("%d", &dynamic_array[i]);
  }

  for (int printf_number = 0; printf_number < elements; printf_number++)
  {
    printf("Element %d: %d\n", printf_number+1, dynamic_array[printf_number]);
  }

  free(dynamic_array);
  dynamic_array = 0;
  return 0;
}

1

solved C I need to use malloc and a dynamically allocated array however I need to print the user input