title: Why does this code only print the last element of a linked list?
body: <pre><code>struct Node{
  int data;
  struct Node* next;
  };
  struct Node* head; 
  void Insert(int x){
      struct Node* temp = (struct Node*)malloc(sizeof(struct Node));
      temp-&gt;data=x;
      temp-&gt;next=NULL;
      head=temp;
  }
  void Print(){
      struct Node* temp=head;
      printf("List is: \n");
      do{
          printf("%d", temp-&gt;data);
          temp=temp-&gt;next;
      }while(temp!=NULL);
  }
  int main(){
      head = NULL; 
      printf("How many numbers do you want to put into a list? \n");
      int n, i, x;
      scanf("%d", &amp;n);
      for (i=0; i&lt;n; i++){
          printf("Enter the number: \n");
          scanf("%d", &amp;x);
          Insert(x);
          Print(); 
      }
  }  
  </code></pre>
  
  <p>this code only prints the last element. I've checked it multiple times, and i can't seem to find the mistake. I would really appreciate If anyone could tell me where did it go wrong.</p>
  
  <p>thanks in advance</p>