title: prime numbers using linked list and recursion in turbo c
body: <p>I was trying to add some linked list to my recursive prime number codes, I was able to store the values using linked list then when I was to retrieve the prime numbers between the two inputted numbers i got this as a result. </p>
  
  <blockquote>
    <p>for input 1 and 5: <code>1,      21,     301,    5</code></p>
  </blockquote>
  
  <p>output should be: </p>
  
  <blockquote>
    <p>2, 3, 5</p>
  </blockquote>
  
  <p>the code is:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;math.h&gt;
  #include&lt;stdlib.h&gt;
  
  struct node
  {
      //struct node *prev;
      int num;
      struct node *nxt;
  }*head;
  
  void store(int value){
      struct node *var, *temp;
      var = (struct node *)malloc(sizeof(struct node));
      var-&gt;num = value;
      if(head==NULL){
          head = var;
          head-&gt;nxt = NULL;
      }else{
          temp = var;
          temp-&gt;nxt = head;
          head=temp;
      }
  }
  
  void accept(int value, int i){
      if(i&lt;2){
          printf("Enter value: ");
          scanf("%d", &amp;value);
          store(value);
          i++;
          accept(value,i);
      }
  }
  
  void prime(){
      int num,x,y;
      struct node *temp,*temp2,*var;
      temp = head;
      temp2 = temp-&gt;nxt;
      y = temp-&gt;num;
      x = temp2-&gt;num;
      primeloop(x,y);
  }
  
  int primeloop(int x,int y){
      int num;
      if ( x == 1 ) x++;
      if(x &lt;= y){
          num = isPrime(x,2); // second input parameter added
          printf("%d",num);
          if(num == 0){
               printf("");
           }else{
               printf("%5d",x);
           }
          primeloop(x+1,y);
      }
  }
  
  int isPrime(int n, int i){
      if(n%i==0 &amp;&amp; n!=2 &amp;&amp; n!=i){
        return(0);
      } else {
         if (i &lt; sqrt(n)) {
          return( isPrime(n,i+1) );
      } else
       return(1);
      }
  }
  
  void main(){
      int i,value;
      clrscr();
      i = 0;
      accept(value,i);
      prime();
      getch();
  }
  </code></pre>
  
  <p>I had to change some lines to make it work with linked list, I could be missing something here since the algo is still the same. Do point out what I did wrong.</p>