Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CSIT231-Sys. Prog. 4/2/22
- // Justin Trubela & Edward Wynman - Lab7
- /*
- Might need to cp Dropbox items like beer.c, ffiles.c, fibonacci.c, and maybe test.out
- */
- #include <time.h> //enable clock_gettime()
- #include <sys/stat.h>
- #include <stdio.h>
- #include <string.h>
- // #include <math.h> //try to use?
- // #include <stdlib.h> //try to use?
- // #include <unistd.h> //try to use?
- //you must declare the "stop" and "start" variables as follows...
- // struct timespec start stop;
- // Timespec struct - Grabbing the time.. for this the variables are "stop" and "start"
- struct timespec {
- //declare the "stop" and "start" variables
- //to capture the start time and then, when the function is finished
- long start; //clock_gettime(CLOCK_REALTIME, &start);
- //to capture the stop time and then, when the function is finished
- long stop; //clock_gettime(CLOCK_REALTIME, &stop);
- //You will now have two data filled variables named "start" and stop" to use but they have 2 properties...
- time_t tv_sec; //time_t data type seconds variable named tv_sec
- long tv_nsec; //long data type nanoseconds variable named tv_nsec
- // figure out how to use these
- }
- int main (int argc, char **argv){
- // 1. Write 2 functions:
- // A: The first function will recursively calculate a Fibonacci sequence number
- // B: The second function will calculate the same WITHOUT using recursion.
- // The inputs of both functions will be a single integer
- // indicating which number in the series you will calculate.
- // 2. You will input, on the command line, a number for which these sequences will be calculated.
- // So, if I enter 5, your program will calculate the first 5 positions of the Fibonacci sequence both ways.
- // 3. Before starting the process:
- // A: grab the start time of the entire process within the maximum time precision available including nanoseconds.
- // You will capture this time at the end of the ENTIRE process the same way.
- // You will use these to calculate the entire time ALL the calculations took to run.
- // 4. For each number, whose Fibonacci sequence is calculated:
- // grab the start time before the function is called the first time
- // and then grab it again when it returns for the final time.
- // Calculate how long that number in the sequence took to calculate.
- // Remember, you are calculating it 2 ways, so you need two start and stop times
- // (recursive and non-recursive) for each.
- // Please grab 10 samples of each and calculate the average time for EVERY NUMBER calculated in the series.
- // 5. If the file does not already exist:
- // create a file called fibonacci.out and put the date and time of the run right on top.
- // The date should read in THIS FORMAT... November 12, 1962 23:00.123456789.
- // 6. To fibonacci.out:
- // for each number calculated in the series:
- // 1. append the sequence number,
- // 2. the calculated result,
- // 3. the calculated average:
- // a: the calculated average recursive time and
- // b: the calculated average non-recursive time
- // SEPARATED BY TABS or COMMAS (important...you'll see why soon).
- // 7. At the end of the run:
- // add the date and time of the run completion in the same format: November 12, 1962 23:00.123456789.
- // 8. State how long the entire process took to complete at the VERY end.
- // 9. Transfer this file to your PC and graph it in Excel. (one line for recursive, one line for non-recursive).
- // Time should be the Y-axis and sequence number should be the X-axis.
- // (explains why I wanted this tab or comma delimited!!!)
- // 10. Set the permissions to fibonnacci.out so that it is "write-protected"
- // (no one has "write" privilege) but can be read by anyone who can log into Turing.
- return 0;
- }
- /*
- ----------------------------------------------------------------------------------------------------
- Here is a sample of what the file should look like after running "./lab7 15"
- November 12, 1962 23:00:00.123456789
- Sequence Result Recursive-time Non-Recursive-time
- 1 1 0.123456789 0.34567890
- 2 1 1.123456789 1.34567890
- 3 2 3.123456789 4.34567890
- 4 3 5.123456789 7.34567890
- 5 5 11.123456789 12.34567890
- 6 8 15.123456789 19.34567890
- 7 13 20.123456789 25.34567890
- 8 21 28.123456789 32.34567890
- 9 34 40.123456789 45.34567890
- 10 55 55.123456789 57.34567890
- 11 89 72.123456789 77.34567890
- 12 144 94.123456789 97.34567890
- 13 233 120.123456789 122.34567890
- 14 377 149.123456789 152.34567890
- 15 610 200.123456789 201.34567890
- November 12, 1962 23:04:00.345678912
- Total Time = 4:00.222222123
- */
Add Comment
Please, Sign In to add comment