Question

In: Computer Science

C Code Please! Declares a constant variable N and sets it to 42. * Declares an...

C Code Please!

Declares a constant variable N and sets it to 42.

* Declares an array of integers, with N elements, called fibonacci.

* Declares an array of double floating-point numbers, with N-1 elements, called ratio.

* Fills the fibonacci array with the numbers in the Fibonacci sequence (Wikipedia is your friend if you don't know what this sequence is about but you want to know).

   Into the i-th element of the fibonacci array, you need to put the i-th term of the Fibonacci sequence.

   The Fibonacci sequence is defined like follows:

    -   The 0-th term fib[0] is 1

    - The 1-th term fib[1] is 1

    - For all other terms with i=2...., the i-th term fib[i] is the sum of the (i-1)-th term fib[i-1] and the (i-2)-th term fib[i-2].

* The program then prints the terms of the Fibonacci sequence, one number per line.

* The program then fills the elements of the ratio array with the *real-valued* quotient of consecutive terms of the Fibonacci sequence.

This means, ratio[i] contains fib[i+1] divided by fib[i].

* The program then prints the elements of the ratio array, one number per line.

Solutions

Expert Solution

CODE FOR THE FOLLOWING PROGRAM:-

#include <stdio.h>

int main()
{
    
    const int N=42; 
    int fibonacci[N];
    double ratio[N-1];
    int first=1,second=1,nextTerm,i=0;
    fibonacci[i]=first;
    
    //Filling the fibonacci array with the numbers in the Fibonacci sequence 
    for(i=1;i<N;i++){
        fibonacci[i]=second;
        nextTerm=first+second;
        first = second;
        second = nextTerm;
    }
    
    //printing the terms of the Fibonacci sequence, one number per line.
    printf("The Fibonacci sequence is: \n");
    for(int i=0;i<N;i++){
         printf(" %d\n",fibonacci[i]);
    }
   
   //Filling ratio array with the *real-valued* quotient of consecutive terms of the Fibonacci sequence.
    for(int j=0;j<N-1;j++){
        ratio[j]=((double)fibonacci[j+1]/(double)fibonacci[j]);
    }
    
    //printing the elements of the ratio array, one number per line.
    printf("The ratios of Fibonacci sequence is: \n");
    for(int i=0;i<N-1;i++){
         printf("%lf\n",ratio[i]);
    }
    return 0;
}

SCREENSHOT OF THE CODE AND SAMPLE OUTPUT:-

SAMPLE RUN:-

HAPPY LEARNING


Related Solutions

1. Select the answer that declares a variable named c that is a C character, initialized...
1. Select the answer that declares a variable named c that is a C character, initialized to the value A. char *c = 'A'; char c = 'A'; char c = "A"; char *c = "A"; 2. Fill in the missing code to produce the desired output: int a = 0; int b = 1; int c; // Missing code goes here printf("%d", c); Desired output: 1 -c = a && b; -c = a || b; -Answer not given...
Complete the following C# code that declares an array of 7 integers. The application allows the...
Complete the following C# code that declares an array of 7 integers. The application allows the user three options: l. to view the elements of array in reverse order, from the last to first position, 2. to choose a specific position to view, 3. quit the program
Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant...
Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant float variable NJSALES_TAX; declares and initializes to 1000 an integer variable total; declares and initializes to zero a float variable grand_total; prompt and input on new line total; calculate grand_total to equal total plus (total*NJSALES_TAX); if grand_total <= 1000 print on new line “Grand total is less than or equal to 1000 it is $” and the grand_total to two decimal places; else if...
in C please! Write a code that asks user for input N and calculates the sum...
in C please! Write a code that asks user for input N and calculates the sum of the first N odd integers. There should be a "pure" method that calculates the sum separately that Main method should call when printing the output.
Constant Current Code for Arduino Develop a Constant Current Program in C and upload it into...
Constant Current Code for Arduino Develop a Constant Current Program in C and upload it into your Arduino #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ *...
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ * This program takes a puzzle board and returns true if the * board is solvable and false otherwise * * Example: board 3 6 4 1 3 4 2 5 3 0 * The goal is to reach the 0. You can move the number of spaces of your * current position in either the positive / negative direction * Solution for this game...
please submit the C code( no third party library). the C code will create output to...
please submit the C code( no third party library). the C code will create output to a file, and iterate in a loop 60 times and each iteration is 1 second, and if any key from your keyboard is pressed will write a 1 in the file, for every second no key is pressed, will write a 0 into the output file.
Explain standards and code sets
Explain standards and code sets
please write the code in C not c++, and not to use Atoi or parseint to...
please write the code in C not c++, and not to use Atoi or parseint to parse the string, Thank you. #include <stdio.h> #include <stdbool.h> /* * The isinteger() function examines the string given as its first * argument, and returns true if and only if the string represents a * well-formed integer. A well-formed integer consists only of an * optional leading - followed by one or more decimal digits. * Returns true if the given string represents an...
For each of the following write the line(s) of code that: Declares and initializes (creates) an...
For each of the following write the line(s) of code that: Declares and initializes (creates) an ArrayList that holds String objects Adds to your ArrayList the words "Too" and "Fun" Verifies that your ArrayList now contains 2 elements Sets the second String in the ArrayList to "No" Verifies that your ArrayList still contains exactly 2 elements Prints the contents of the ArrayList to the screen in the following format: <element>, <element>, . . . , <element>
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT