answersLogoWhite

0


Best Answer

In c:

int fibr(int n) { // Find nth Fibonacci number using recursion.

if (n<=2) return 1; // the first two Fibonacci numbers are 1 and 1

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

}

int fibi(int n) { // Find nth Fibonacci number using iteration.

int temp,last=1,f=1;

int i;

for (i=3;i<n;++i) { // the first two Fibonacci numbers are 1 and 1

temp=f;

f+=last;

last=temp;

}

return f;

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

f_1= 1;

f= 1;

for (i=3; i<=n; ++i) {

f_2 = f_1;

f_1 = f;

f= f_1 + f_2;

}

printf ("f(%d)=%d\n", n, f);

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to generate the Fibonacci series using non-recursive method?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Fibonacci retracement refers to what type of method of analysis?

The term 'Fibonacci retracement' refers to a method of technical analysis for studying the support and resistance level. This term was developed after they used the Fibonacci sequence.


Who invented the fibinacci method?

Leonardo Fibonacci of Pisa. Not fibinacci!


How old was Fibonacci when he published his book liber abaci?

Fibonacci, b 1170, published his book in 1202. He decided the Arabic method of arithmetic was much superior to the Roman one. And he was right!


Could you write a java program that randomly generate a number plate for a car registration using the random method from Maths class eg NLF810?

yes, use for loop;;


What is the most efficient method for a facultative anaerobic cell to generate ATP?

Aerobic respiration is the most efficient method for a facultative anaerobic cell to generate ATP.


What is the name of the mathematical pattern 1 1 2 3 5 8 13 15?

Fibonacci method


How to write program for secant method in mathematica?

How to write a program for secant method by mathematica


The main method of a program has?

The Java main method of a program is the place where the program execution begins. A main method would look like below public static void main(String[] args){ }


What JavaScript method is most commonly used to generate output?

alert and prompt


Write a java application that generates two random numbers using built in method math random ranging 5 to 8 the program should use another built in method to calculate the power of xy the x value is t?

write a java application that generate custemer account balance in a banking system?


Differences between declaring a method and calling a method?

Declaring a method is when you code for what the method will perform. When you call a method, you are using the method you have written in another part of the program, (or inside the method if it is recursive).


What happens if the static modifier is removed from the signature of the main program in java?

Actually speaking nothing major happens. That method would become just another method in the class. You cannot use that as the method to begin the program execution in your class. Your class will not be a standalone java program and you cannot execute it like you did before using the public static void main() method.