Question: I need help writing this fibonacci sequence program in C. These are the function requirements. It has to include a header file for big50.h and

I need help writing this fibonacci sequence program in C. These are the function requirements. It has to include a header file for big50.h and can't have a main function. Header file is:

_____

#ifndef __BIG50_H #define __BIG50_H

#define MAX50 50 //const int MAX50=50;

typedef struct Integer50 { // a dynamically allocated array to hold a 50 // digit integer, stored in reverse order int *digits; } Integer50;

typedef struct big50RatingStruct{ char *NID; //pointer to a malloc'ed buffer for the NID float degreeOfDifficulty; //1.0 for super easy to 5.0 for insanity++ float duration; // Hours spent writing, reading, // designing & building the code } big50RatingStruct;

char *cryptoVariableFilename; // for the filename

int seed;//to seed the RNG or not

int nFib; //control the number of Fibonacci numbers to calculate

Integer50 *cryptoVariable; // 50 digits of used to start the F[x]

Integer50 *hwConfigVariable; // 50 digits of psuedo or real // randomness to start the F[x] // Functional Prototypes

Integer50 *big50Add(Integer50 *p, Integer50 *q);

Integer50 *big50Destroyer(Integer50 *p);

Integer50 *fibBig50(int n, Integer50 *first, Integer50 *second);

void big50Rating(void);

Integer50 *parseString(char *str);

Integer50 *loadHWConfigVariable(int doSeed);

Integer50 *loadCryptoVariable(char *inputString);

#endif

_____

Integer50 *big50Add(Integer50 *p, Integer50 *q);

Description: Return a pointer to a new, dynamically allocated Integer50 struct that contains the result of adding the 50 digit integers represented by p and q. Special Notes: If a NULL pointer is passed to this function, simply return NULL. If any dynamic memory allocation functions fail within this function, also return NULL, but be careful to avoid memory leaks when you do so. Hint: Before adding two huge integers, you will want to create an array to store the result. Remember that all integers in this problem are 50 digits long. In the event that the most significant digits (MSD) result in a carry, the carry will be ignored. For example, if the MSD of the two inputs are 9 and 7, the resultant MSD will be 6 with a carry of 1 for the MSD + 1 digit. (9 + 7 = 16, therefore 6 is the MSD and the 1 is ignored.) Returns: A pointer to the newly allocated Integer50 struct, or NULL in the special cases mentioned above.

____ Integer50 *i50Destroyer(Integer50 *p); Description: Destroy any and all dynamically allocated memory associated with p. Avoid segmentation faults and memory leaks. Returns: NULL

_____ Integer50 *parseString(char *str); Description: Convert a number from string format to Integer50 format. (For example function calls, see big50-main01.c.) Special Notes: If the empty string () is passed to this function, treat it as a zero (0). If any dynamic memory allocation functions fail within this function, or if str is NULL, return NULL, be careful to avoid memory leaks when you do so. You may assume the string will only contain ASCII digits 0 through 9, for a minimum of 50 digits. In the event that 50 digits are not in the input string, print an error message to STDERR and fill with leading zeroes. Also, if there are more than 50 digits in the input string use the first 50 digits in the string. Returns: A pointer to the newly allocated Integer50 struct, or NULL if dynamic memory allocation fails or if the input str is NULL.

___

Integer50 *fibBig50(int n, Integer50 *first, Integer50 *second);

Description: This is your Fibonacci function. Pay careful attention the F(0) is initialized with the hwConfigVariable and F(1) is initialized with the cryptoVariable. Implement an iterative solution that runs in O(n) time and returns a pointer to a Integer50 struct that contains F(n). Be sure to prevent memory leaks before returning from this function. Space Consideration: When computing F(n) for large n, its important to keep as few Fibonacci numbers in memory as necessary at any given time. For example, in building up to F(10000), you wont want to hold Fibonacci numbers F(0) through F(9999) in memory all at once. Find a way to have only a few Fibonacci numbers in memory at any given time over the course of a single call to fibBig50(...). Special Notes: Remember that n is the second parameter passed as an input argument to the program. You may assume that n is a non-negative integer. If any dynamic memory allocation functions fail within this function, return NULL, but be careful to avoid memory leaks when you do so. Returns: A pointer to an Integer50 representing F(n), or NULL if dynamic memory allocation fails.

___

Integer50* loadHwConfigVariable(int seed); Returns: A pointer to an Integer50 array of 50 random digits. If the input variable seed is set, the random number generator will be seeded, otherwise not. Regardless, the 50 digits will be initialized in 10 unique groups of 5 random digits. Returns NULL if there is an error during creation or initialization of the hwConfigVariable.

___

Integer50* loadCryptoVariable(char *cryptoVariableFilename); Returns: A pointer to an Integer50 array of 50 random digits read in from the cryptoVariable- Filename. Returns NULL if there is an error during initialization of the cryptoVariable or in the file I/O.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!