Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The nth Fibonacci number is defined as the sum of the previous two Fibonacci numbers. The first and second Fibonacci numbers (which are needed to

The nth Fibonacci number is defined as the sum of the previous two Fibonacci numbers. The first and second Fibonacci numbers (which are needed to get the recurrence started) are 0 and 1, respectively. Write a function that takes a single argument, an int* that corresponds to an array of size (at least) 3. The precondition of the function is that the first two elements of the array are the (n-2) and (n-1) Fibonacci numbers.The function should compute the nth Fibonacci number and place it in the third element of the array.

Fill in the following main function so that it fills the first n Fibonacci numbers into the fib array. Use the function you defined above to compute each number.

int main(){

const int n = 25;

int fib[n];

int i;

fib[0] = 0;

fib[1] = 1; /* fill this in */

}

I have so far:

#include int main(){ const int n = 25; int fib[n]; int i; //loop fib[0] = 0; fib[1] = 1; for(i = 2; i < 25; i++){ fib[i] = fib[i-1] + fib[i-2]; } for(i = 0; i < 25; i++){ printf("feb %d is %d ",fib[i]); } return 0; }

How do I make a seperate function fib() and how to implement pointers?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

design a simple performance appraisal system

Answered: 1 week ago