23 May Please Use C Language To Figure Out Problems
Problem 1 (15 points)
The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8, . . . Formally, it is expressed as
fib0 = 0
fib1 = 1
fibn = fibn-1 + fibn-2.
Write a complete C program that spawns n process which cooperate to compute and print the first n Fibonacci numbers, where n is given as a command-line argument, such that each process computes and prints only one number in the sequence. The processes must terminate in reverse order of creation. Be careful to synchronize the processes so that the numbers are printed in the correct order. For instance:
1 $ ./a . out 2
2 0 1
3 $ ./a . out 3
4 0 1 1
5 $ ./a . out 4
6 0 1 1 2
7 $ ./a . out 5
8 0 1 1 2 3
9 $ ./a . out 6
10 0 1 1 2 3 5
11 $ ./a . out 7
12 0 1 1 2 3 5 8
13 $ ./a . out 12
14 0 1 1 2 3 5 8 13 21 34 55 89
15 $
Problem 2 (15 points)
This exercise is an extension of project 2 (problem 2). Specifically, extend your solution so that the lines read represent Linux commands to be executed. After the command line is tokenized and stored in the array of arguments, rather than printing it, fork a child and then have the parent wait for the child and have the child execvp the Linux command using the argument vector. This time print a prompt for input to standard error, as shown below. For instance:
1 $ gcc ourshell. c −o ourshell
2 $ ./ourshell
3 ourshell> date
4 Wed Feb 10 1 0 : 5 9 : 2 7 EST 2016
5 ourshell> hostname
6 cpssuse07
7 ourshell> uname
8 Linux
9 ourshell> uname −a
10 Linux cpssuse07 3.11.10−29−desktop #1 SMP PREEMPT Thu Mar 5 1 6 : 2 4 : 0 0 ←֓
UTC 2015 (338 c513 ) x86_64 x86_64 x86_64 GNU/Linux
11 ourshell> wc −l
12 hello world
13 good
14 bye
15 ^D
16 3
17 ourshell> ls −l −a ~/.profile
18 −rw−−−−−−− 1 lucia wheel 2087 Aug 11 2015 . profile
19 ourshell>
20 ourshell> cal 9 1752
21 September 1752
22 Su Mo Tu We Th Fr Sa
23 1 2 14 15 16
24 17 18 19 20 21 22 23
25 24 25 26 27 28 29 30
26 ourshell> gcc parsestring. c −o parsestring
27 ourshell> ./parsestring
28 one two three four
29 : one :
30 : two :
31 : three:
32 : four :
33 ls −a −l myfile
34 : ls :
35 :−a :
36 :−l :
37 : myfile:
38 ^D
39 ourshell> lsss
40 ./ourshell: lsss : No such file or directory
41 ourshell> ./parsestring1
42 ./ourshell: ./parsestring1: No such file or directory
43 ourshell> ^D
44 $
Project 2 (problem 2)
2. This programming exercise is a modification of the problem above. The command-line arguments expected are the same, and the same errors should be handled in the same manner. The difference is that this program must remove all occurrences of the first string in the second string, and the resulting string and the number of occurrences that were found/removed must be written to standard output.
The following are some sample, non-exhaustive test cases. Your program is expected to produce identical output. Do not prompt for input.
1 $ ./a . out hehe xxxheheheyyy −nooverlap
2 1
3 xxxheyyy
4 $ ./a . out hehe xxxheheheyyy
5 2
6 xxxyyy
7 $ ./a . out xx xxxheheheyyy
8 2
9 heheheyyy
10 $ ./a . out yy xxxheheheyyy −nooverlap
11 1
12 xxxhehehey
13 $ ./a . out qq xxxheheheyyy −nooverlap
14 0
15 xxxheheheyyy
16 $ ./a . out qq
17 Usage : string1 string2 [−nooverlap]
18 $ echo $?
19 1
20 $ ./a . out “” “”
21 Search string cannot be empty!
22 $ echo $?
23 1
24 $ ./a . out hello “”
25 0
26
27 $
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
