title: Looking for a different logic
body: <p>so i wrote this unfinished but working code. im a very new to programming and i think that my logic is wrong (although code is running properly) because there is too many "ifs and elses" i cant think of another working logic to insert data to any position of the linked list and output the data + error handling if position is invalid im trying to develop computational thinking
  and something tells me this code can be wrote much better</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  struct node {
      int data;
     struct node* next;
  };
  
  struct node* head = NULL;
  
  
  void Insert(int c ,int e)
  {
      int i;
      static int p = 1;
      struct node* temp = malloc(sizeof(struct node));
      temp -&gt; data = c;
      temp -&gt; next = NULL;
     struct node* temp1 = head;
  
      if (e &gt; p+1)
      {
          printf("Invalid Position");
          return;
      }
  
     else if (head == NULL)
          {
          head = temp;
          return;
          }
  
      else if (e &lt;= 1)
      {
          temp -&gt; next = head;
          head = temp;
          return;
      }
  
      else if (e == 2)
      {
          if (temp1 -&gt; next != NULL)
          {
              temp -&gt; next = temp1 -&gt; next;
              temp1 -&gt; next = temp;
  
          }
  
          else
          {
              temp1 -&gt; next = temp;
  
          }
  
      }
  
      else
      {
          for (i = 0;i&lt;e-2;i++)
          {
              temp1 = temp1 -&gt; next;
          }
  
      temp -&gt; next = temp1 -&gt; next;
      temp1 -&gt; next = temp;
      }
  p++;
  }
  
  void print() {
  
      struct node* temp = head;
      printf("list is: \n");
      while (temp != NULL) {
  
          printf( "%d ,",temp-&gt;data);
          temp = temp-&gt;next;
      }
  }
  
  
  int main () {
  
  printf("How Many Numbers?\n");
  int a ,b ,c, e;
  scanf("%d" , &amp;b);
  for(a = 0;a&lt;b;a++) {
      printf("Enter the numbers \n");
      scanf("%d",&amp;c);
      printf("Enter position \n");
      scanf("%d",&amp;e);
      Insert(c , e);
      print();
  }
  return 0;
  }
  </code></pre>