![]() |
|
E-Learning Center « E-Learning tutorials and competitions. » |
![]() |
|
Share | Thread Tools | Search this Thread |
![]() |
#1 |
Registered Member
Last Online: 06-20-2011
Join Date: Mar 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
|
![]()
plz some help for my project i don't know how to do it
Operating System ===> Ubuntu ====> C language The Project Is: The Fibonacci Sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8, .... Formally, it can be expressed as: fib0 = 0; fib1 = 1; fibn = fibn-1 + fibn-2; Write a program C using the fork() system call that generates the fibonacci sequence in the child process. the number of sequence will be provided in the command line. for example, if 5 is provided, the first numbers in the fibonacci sequence will be output by the child process. because the parent and child processes have their own copies of data, it will be necessary for the child to output sequence. have the parent invoke the wait() call to wait for the child process to complete before exiting the program. perform the necessary error checking to ensure that non-negative number is passed on the command line. |
![]() |
![]() |
![]() |
#2 |
Last Online: 06-12-2019
Join Date: Mar 2006
Posts: 6,245
Thanks: 2,120
Thanked 3,365 Times in 1,740 Posts
Groans: 29
Groaned at 44 Times in 35 Posts
|
![]()
I'm not sure if this is what you want, but give it a try:
Code:
#include <stdio.h> int main(){ int i; do{ printf("Input Number: "); scanf("%d", &i); }while(i < 0); if(fork()==0){ int j; int fibn=0; int fibnminus1=0; int fibnminus2=0; for(j = 0; j < i; j++){ fibnminus2 = fibnminus1; fibnminus1 = fibn; if(j < 2) fibn = j; else fibn = fibnminus1+fibnminus2; printf("%d, ", fibn); } printf("...\n"); return 0; }else{ wait(); } return 0; }
__________________
What we do in life, echoes in eternity.
|
![]() |
![]() |
![]() |
#3 |
Registered Member
Last Online: 06-20-2011
Join Date: Mar 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
|
![]()
Thx Tawa For The Solution
![]() |
![]() |
![]() |
![]() |
|
Tags |
operating |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
|
|