i'm working on a program in c language in which I have to use linked-list and in this program I have to insert the new node at the start of the linked-list if the user pass the value of the place 0 and also insert the new node at the end of the linked-list if the user pass the value of the place 1 in the choice variable. But i'm not getting any output on console and my program ends by just writing Output: I can't figure out the problem in my code and here's my code.
/* 
  program for making nodes and adding them in memory as per 0
  and 1
  0 means that insert the number at front , in other words insert number after head 
  1 means insert number at the last place
  First you need to input a number and then enter the place you want to insert it by giving input as 0 and 1 
  
  *Recall what does 0 and 1 mean by looking at line 5-7 respectively. 
  
  Just like 
  5 0 6 1 7 0 8 1
*/
#include <stdio.h>
#include <stdlib.h>
// declaring struct with typedef for ease of use
typedef struct node
{
  int data;
  struct node *next;
}node;
// declarations of functions use for this program respectively
void free_node(struct node *head);
void insert_at_beg(int num, struct node *head);
void insert_at_end(int num, struct node *head);
void print_node(struct node *head);
int main(void)
{
  struct node *head = NULL;
  int n;
  // taking input
  printf("Input number of nodes: ");
  scanf("%d",&n);
  int num, choice;
  printf("\nInput data for nodes->\n");
  // loop which takes value and choice 
  for (int i = 0; i < n; i++)
  {
    num = 0, choice = 0;
    printf("\nInput data for the %d node: ", i+1);
    scanf("%d",&num);
    do
    {
      printf("Input place for the %d node: ", i+1);
      scanf("%d",&choice);
    }
    while (choice != 1 && choice != 0);
    
    if (choice == 0)
    {
      // function to insert node at front of head
      insert_at_beg(choice, head);
    }
    else 
    {
      // function to insert node at last place
      insert_at_end(choice, head);
    }
  }
  
  // function to print nodes
  print_node(head);
  
  // function to free memory made by malloc()
  free_node(head);
}
// function to free the nodes 
void free_node(struct node *head)
{
  struct node *temp = head;
  while(temp != NULL)
  {
    free(temp);
    temp = temp->next;
  }
}
// function for inserting number at front
void insert_at_beg(int num, struct node *head)
{ 
  struct node *new_node = malloc(sizeof(node));
  if (new_node == NULL)
  {
    printf("Can't allocate memory.");
    exit (1);
  }
  new_node->data = num;  
  new_node->next = head;
  head = new_node;
}
// function for inserting node at end
void insert_at_end(int num, struct node *head)
{
  struct node *new_node, *last_node = NULL;
  new_node = malloc(sizeof(node));
  if (new_node == NULL)
  {
    printf("Can't allocate memory.");
    exit (1);
  }
  if (head == NULL)
  {
    new_node->data = num;
    new_node->next = NULL;
    head = new_node; 
  }
  
  last_node = head;
  new_node->data = num;
  new_node->next = NULL;
  while (last_node->next != NULL)
  {
    last_node = last_node->next;
  } 
  last_node->next = new_node;
}
//function for printing nodes
void print_node(struct node *head)
{
  printf("\nOutput: \n");
  struct node *temp = head;
  while(temp != NULL)
  {
    printf("%d ",temp->data);
    temp = temp->next;
  }
}
 
     
    