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
(tco 8) when a file is opened in the append mode, the file pointer is positioned
Artyom0805 [142]
At the end of the file, so that additional data is appended while the existing data stays intact.
6 0
4 years ago
What ip class is this address: 128-191.255.255.255?
defon
Class B would be the correct answer.
4 0
4 years ago
What is the output of 1101×10==11000+10
aliya0001 [1]

Answer:

west ward cpt output

Explanation:

i know because i invented it

6 0
3 years ago
Read the following characteristic:
Ivanshal [37]

Answer:

A goal of procedural programming

An advantage of object oriented programming

A disadvantage of object oriented programming

A drawback of procedural programming

3 0
2 years ago
Lindsay owns a candy store that typically makes all of its sales to tourists visiting a nearby zoo. Why might she decide to set
umka2103 [35]
Social media is so powerful in this generation because it is able to reach many different corners of the world. It is not only used merely for communication but also sometimes or most of the times for business. For Lindsay, the use of social media will allow her to increase the size of the customer base. The answer is letter A. 
4 0
4 years ago
Read 2 more answers
Other questions:
  • Some files appear dimmed in one of the default folders on your computer. What would be the best course of action? A. Leave the f
    11·1 answer
  • You're the network administrator for a company that has just expanded from one floor to two floors of a large building, and the
    7·1 answer
  • Give sally sue specific suggestions on how she can improve her powerpoint skills.
    6·1 answer
  • Which letter would appear in the third position of the standard wheel marking of a hard-grade wheel?
    10·2 answers
  • Public class Main{ public static void main(String [] args){ String name=WelcomeJava; Runnable r1=() -&gt; System.out.println(nam
    12·1 answer
  • Bored can you talk to me
    5·2 answers
  • What is the output of the following program? If there is any problem, how can
    13·1 answer
  • Which statement about intellectual property is true? (CSI-7.6) Group of answer choices It is okay to use code you find on the in
    14·1 answer
  • Write about virus in five points.​
    8·1 answer
  • Explain how communication facilitate cordination​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!