C Programming. Spread code across multiple files. Create Fibonacci function. Store in array.

C Programming

Do not edit main.c in this lab assignment! However, notice that the function compute_fibs() is not defined.

Instead of adding the definition of compute_fibs() directly to main.c, your job is to create two additional files and add them to your project:

  1. mymath.h -- This file should contain the function declaration for the compute_fibs() function you are going to define in mymath.c
  2. mymath.c -- This file will contain the function compute_fibs() that computes the 1st N elements of the Fibonacci sequence. These N elements will be stored sequentially into the array fibs that was passed into the function by reference. The declaration of this function looks like this:

void compute_fibs (unsigned long int *fibs, unsigned int *N);

Your compute_fibs() function should be smart enough to return early if the numbers in the Fibonacci sequence become too large to be stored into an unsigned long int. If this happens, update the data referenced by the variable N that was passed into the function to contain the number of elements in the Fibonacci sequence you actually computed before being forced to return early.


  • Use the macro ULONG_MAX defiend in limits.h. You will need to do a little math to check the inequality properly (i.e. foo > ULONG_MAX won't work since foo can't store values bigger than ULONG_MAX if foo is an unsigned long!)



#include "mymath.h"

#define ELEMENTS 100

int main ()


    unsigned int i;

    unsigned long int fibs[ELEMENTS];

    unsigned int n = ELEMENTS;

    compute_fibs (fibs, &n);

    for (i=0; i printf ("fibs[%i]: %lu\n", i, fibs[i]);

        printf ("Displaying %u fibs\n", n);

    return 0;


Get Help With a similar task to - C Programming. Spread code across multiple files. Create Fibonacci function. Store in array.

Login to view and/or buy answers.. or post an answer

Related Questions

Similar orders to C Programming. Spread code across multiple files. Create Fibonacci function. Store in array.
Java Customer Program
Problem 1: Customer Max has opened his own pet supply store so he can help himself to treats and toys whenever he wishes. In order to encourage customers to shop at his store more, he is implementing a customer loyalty program. For every $100 spent, the c...
Literature Review for Smart Case for tracking monitoring and tracing packages being delivered
They're three attachments below one being the handbook to help guidance during this progress another being the first proposal of the project and then the assignment that needs completing, the Literature review....
c++ lab 1 intro lab
P ROBLEM STATEMENT: A review and extension of cs132: sort a file with 120 records. However, due to memory restrictions only 20 records may be placed into memory. You are to implement a “quasi” external sort CODE/DIRECTIONS: For the sake of si...
Cryptography Assignment C
1. Write two programs that use some of the build-in Cryptographic APIs a. Write one C program that uses Symmetric-Key algorithm b. Write one C program that used Asymmetric-key algorithm c. Use C programming language to write your code d. Make sure tha...