Horje
Print fabionci with fork in C Code Example
Print fabionci with fork in C
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

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", &ii);

   if (ii < 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<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;
}




C

Related
c command line arguments parser Code Example c command line arguments parser Code Example
rust unit test display Code Example rust unit test display Code Example
Rounding Floating Point Number To two Decimal Places in C Code Example Rounding Floating Point Number To two Decimal Places in C Code Example
gandhi ashram saharanpur Code Example gandhi ashram saharanpur Code Example
Palindrome number in c program Code Example Palindrome number in c program Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7