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
Please anyone, help me.... I'm not sure how to put these all together.<br> 35 points!
Vilka [71]

Answer:

#School Name

school_name = "Klein Cain"

# Asks for name

full_name = input("Please enter your full name ")

#Says Hello

print("Hello, ", full_name, "!!")

#Says the letters in your name

print("There is ", len(full_name), " letters in your name")

#Says final message

print("??? is a Cain where??? ", school_name)

7 0
3 years ago
Read 2 more answers
Out-of-order instruction execution can cause problems because a later instruction may depend on the results from an earlier inst
scoundrel [369]

Answer:

C

Explanation:

6 0
3 years ago
PLEASE HELP!!!!! (Environmental Science Semester 1)
uranmaximum [27]
I believe the answer would be B, Sorry if I'm wrong! ❤
6 0
3 years ago
Read 2 more answers
Blair is the director of information systems at a marketing firm. She creates a set of guidelines that dictate everything an emp
gizmo_the_mogwai [7]

Answer:

data

Explanation:

Because i said so

4 0
3 years ago
Defensive programming is sometimes referred to as _________.
Romashka [77]
Anti-malware and Anti-Virus
6 0
3 years ago
Other questions:
  • "which part of an information system consists of the rules or guidelines for people to follow?"
    9·1 answer
  • The ________ multiple-selection PHP statement is used to handle decision making and can be used to replace multiple if and if...
    12·1 answer
  • What are an administrator's choices for managing file permissions on a drive formatted as fat32?
    10·1 answer
  • What is the preferred procedure for putting customers on hold​
    13·2 answers
  • Define the following terms:<br><br> - pigment<br> - vehicle<br> - binder<br><br> plz help
    12·2 answers
  • In an income statement subtracting the cost of goods sold from the net sales provides the?
    11·1 answer
  • An IT professional with a customer-service
    13·1 answer
  • Which of the following file formats cannot be imported using Get &amp; Transform?
    6·1 answer
  • __________ is a broad class of software that is surreptitiously installed on a user's machine to intercept the interaction betwe
    6·1 answer
  • A 4"x6" photo is digitized using 10,000 pixels. An 11"x7" photo is digitized using 30,000 pixels. Which image will have the bett
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!