why program to delete nth node in linked list is running infintely? :     #include<stdio.h>
    #include<stdlib.h>
    struct node{
      int data;
      struct node* next;

    };
    void insert(int x);
    void print();
    
    void deletenode(int n);
    struct node* head;     //global declaration
    int main(){
      int n,m;
      insert(5);
      insert(9);
      insert(2);
      insert(3);  //list is 3,2,9,5;
      print();
      printf("enter the node position you want to delete");
      scanf("%d",&n);
calling deletenode function to delete the node   
   
      deltenode(n);
again printing the list after deletion of nth node 
 
       print();
guys this program is running efficiently when i am not using deletenode function and printing the linked list correctly but after using deletenode function when i am using print function it printing infinitely 
i think there should be no mistake in print function because it is working fine when i am using it above deletenode but after using it below deletenode printing infinitely
i am entering or parsing  all the valid values so i am not making any special case in any function
my delete funtion is 
        
        void deletenode(int n){
         struct node *temp,*temp1;
         temp=head;
         for(int i=0;i<=n-2;i++){
            temp=temp->next;


        }
        temp1=temp->next;
        temp=temp1->next;
        free(temp1);

        }

my print function is 

     void print(){
     struct node* temp;
     temp=head;
     while(temp!=NULL)
     {   printf("%d",temp->data);
     temp=temp->next;

     }
GUYS I KNOW MY PROGRAM IS NOT EFFICIENT IN TERM OF MANY THINGS AS I AM A BEGINNER 
BUT CAN YOU PLEASE TELL ME WHY THIS IS HAPPENING WHERE IS MY ERROR IN THE PROGRAM
i will learn a lot when i get to know from my errors
my insert function is

    void insert(int x){
    struct node *temp=(struct node*)malloc(sizeof(head));
    temp->data=x;
    temp->next=head;
    head=temp; 

    }