1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Darya [45]
3 years ago
9

Using language c, find the nth Fibonacci, knowing that nth Fibonacci is calculated by the following formula: - If n = 1 Or n = 2

then F(n) = 1 - If n>2 then F(n) = F(n-1) + F(n-2)
Computers and Technology
1 answer:
Nina [5.8K]3 years ago
4 0

Answer:

#include <stdio.h>

int fib(int n) {

 if (n <= 0) {

   return 0;

 }

 if (n <= 2) {

   return 1;

 }

 return fib(n-1) + fib(n-2);

}

int main(void) {

 for(int nr=0; nr<=20; nr++)

   printf("Fibonacci %d is %d\n", nr, fib(nr) );

 return 0;

}

Explanation:

The code is a literal translation of the definition using a recursive function.

The recursive function is not per se a very efficient one.

You might be interested in
Top 10 web hosting sites ?
swat32
I have only 5 so hope it helps.

1. bluehost
2. HostGator
3. GoDaddy
4. network solutions
5. web.com
7 0
3 years ago
Read 2 more answers
Jesse is writing a physics quiz about the motion of a roller coaster cart. He has a clip art illustration of a cart rolling hori
Aleks04 [339]
<span>editing the image file in a dedicated photo editing program before inserting it</span>
8 0
3 years ago
What is your definition of Green/Eco Driving?
Masja [62]
Using/driving with an electric car or using car that is ecologically friendly (less pollution) Ex.Bio Fuel
8 0
3 years ago
a key part of staying safe is employing good habits. drag the step number to the proper sequence triple a
solong [7]

Answer:

where are the step number. I can't find any

6 0
3 years ago
1.Siguraduhing _______ang mga datos o impormasyong
Lunna [17]

Answer:

1.maayos

2. Lugar

3. mali

Explanation:

im correct if I'm rwong :-)

7 0
3 years ago
Other questions:
  • What does the word tolerance mean in textiles?
    9·1 answer
  • What technology allows data to be stored in one place and be retrieved by many systems?
    7·1 answer
  • ________ is the amount of data that can be transmitted across a transmission medium in a certain amount of time.
    15·1 answer
  • Computing devices translate digital to analog information in order to process the information
    8·1 answer
  • In order to average together values that match two different conditions in different ranges, an Excel user should use the functi
    6·1 answer
  • Identify a factor that is unlikely to influence the length of time people wait in the lunch line.
    8·2 answers
  • How to improve a poor game design puzzles
    11·1 answer
  • In photoshop what should you consider when determining a projects purpose and objectives?
    15·1 answer
  • How exactly do you find the circumference by using C++ Programming? I really need a specific answer.
    14·1 answer
  • 안녕 또 나야 난 너에게 미래의 메시지를 전하러 왔어 01100011 01101111 01101101 01101111 00100000 01111001 00100000 01101100 01101111 00100000 01101101
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!