Search
 
SCRIPT & CODE EXAMPLE
 

C

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:
");
   scanf("%d", &ii);

   if (ii < 0)
      printf("Please enter a non-negative integer!
");
   else
   {
      pid = fork();
      if (pid == 0)
      {
         printf("Child is producing the Fibonacci Sequence...
");
         printf("%d %d",a,b);
         for (i=0;i<ii;i++)
         {
            n=a+b;
            printf("%d ", n);
            a=b;
            b=n;
         }
         printf("Child ends
"); 
      }
      else 
      {
         printf("Parent is waiting for child to complete...
");
         wait(NULL);
         printf("Parent ends
");
      }
   }
   return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: using tables as arguments in c++/c 
C :: C Create union variables 
C :: golang inline function definition 
C :: profile time bash script 
C :: openinh VCL file for Vivado HLS 
C :: #include <stdio.h int main() { int x = 10, *y, **z; y = &x; z = &y; printf(""%d %d %d"", *y, **z, *(*z)); return 0; } 
C :: FivemStore 
C :: c printf affichage 
C :: how to write 2d array from bin file in c 
C :: navigate to line intellij 
C :: i765 OPT filing fees october 2 
C :: create a buffer in c 
C :: array of string in c 
C :: c make list 
C :: how to do add to an integrr in c 
Dart :: flutter listtile shape 
Dart :: flutter get millis time 
Dart :: flutter check if string is number 
Dart :: flutter copy to clipboard 
Dart :: change hint text color flutter 
Dart :: flutter tooltip circle border 
Dart :: image from internet flutter 
Dart :: flutter linear progress indicator height 
Dart :: flutter listtile color 
Dart :: clickable card flutter 
Dart :: verified publisher account on pub.dev using google blogger 
Dart :: flutter listtile disable 
Dart :: dart qoldiqni olish 
Dart :: elevatebutton in flutter 
Dart :: how to convert timestamp to datetime in dart 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =