title: Printing Fibonacci with fork()
body: <p>The problem I am having is that when say for instance the user enters 7, then the display shows:</p>
  
  <pre><code>0 11 2 3 5 8 13 21 child ends.
  </code></pre>
  
  <p>I cannot seem to figure out how to fix the 11 and why is it displaying that many numbers in the sequence! Can anyone help?</p>
  
  <p>The number of the sequence will be provided in the command line. For example, if 5 is provided, the first five numbers in the Fibonacci sequence will be output by the child process. Because the parent and child processes have their own copies of the data, it will be necessary for the child to output the sequence. Have the parent invoke the wait() call to wait for the child process to complete before exiting the program. Perform necessary error checking to ensure that a non-negative number is passed on the command line. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  
  int main()
  {
     int a=0, b=1, n=a+b,i,ii;
     pid_t pid;
  
     printf("Enter the number of a Fibonacci Sequence:\n");
     scanf("%d", &amp;ii);
  
     if (ii &lt; 0)
        printf("Please enter a non-negative integer!\n");
     else
     {
        pid = fork();
        if (pid == 0)
        {
           printf("Child is producing the Fibonacci Sequence...\n");
           printf("%d %d",a,b);
           for (i=0;i&lt;ii;i++)
           {
              n=a+b;
              printf("%d ", n);
              a=b;
              b=n;
           }
           printf("Child ends\n"); 
        }
        else 
        {
           printf("Parent is waiting for child to complete...\n");
           wait(NULL);
           printf("Parent ends\n");
        }
     }
     return 0;
  }
  </code></pre>