answersLogoWhite

0

int main(const int argc, const char** argv) {

// Usage:

// print the first 10 Fibonacci numbers recursively
fib_rec(10);

// print the first 10 Fibonacci numbers iteratively
fib_it(10);

return 0;

}

// simple starting interface for recursive algorithm
void fib_rec(const unsigned int max) {

printf("F0 = 0\n");
_fib_rec(0, 1, 1, max);

}

// recursive part of algorithm

void _fib_rec(const unsigned int f0, unsigned const int f1, unsigned const int current, unsigned const int max) {
printf("F%d = %d\n", current, f1);

if(current < max) {
_fib_rec(f1, f0 + f1, current + 1, max);

}

}

// iterative solution
void fib_it(const unsigned int max) {

int current;
int f0 = 0;
int f1 = 1;
int temp;

printf("F0 = 0\n");
for(current = 1; current <= max; ++current) {
printf("F%d = %d\n", current, f1);
temp = f0;
f0 = f1;
f1 = temp + f1;

}


}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


Can you explain the program of Fibonacci series in c?

You mean you have written a program, but you don't understand it? Well, how could I explain it without seeing it?


Program to generate Fibonacci series using storage class in c plus plus?

i dn't know. haha


Write a program using while loop that generates Fabonaci series up to 200?

//to generate Fibonacci series upto a range of 200....(in C).... #include&lt;stdio.h&gt; main() { int a,b,c,i; a=0; b=1; printf("\n FIBONACCI SERIES .....\t"); i=1; while(i&lt;=(200-2)) { c=a+b; printf("\t%d",c); a=b; b=c; i++; } }


Can you have the program in C plus plus for recursive function generating a series of terms?

Yes, this can be done. For example for Fibonacci series. You will find plenty of examples if you google for the types of series you need to be generated.


Create a c plus plus program to generate Fibonacci series?

#include #include void main() { clrscr() int a=0,b=1,c,i,n; coutn cout


Program that generates and displays the Fibonacci?

/*WAP to display Fibonacci series*/ #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int i,a=0,b=1,c; scanf("%d",&amp;n); printf("%d\n%d",a,b); for(i=0;i&lt;n;i++) { c=a+b; a=b; b=c; printf("\n%d",c); } getch(); }


How do you write prime number program in C language?

[ Fibonacci series___: ] #include&lt;stdio.h&gt; int main(void) { int n,i,c,a=0,b=1; printf("Enter Fibonacci series of nth term : "); scanf("%d",&amp;n); printf("%d %d ",a,b); for(i=0;i&lt;=(n-3);i++) { c=a+b; a=b; b=c; printf("%d ",c); } }


Write a C program Fibonacci using normal loops and conditional statements?

to print the Fibonacci series until 100 you can take the input in d to make it run for whatever value you want void main(){ int a,b,c,d; a=0; b=1; c=1; d=100; while(c&lt;d) { printf("%d\n",c); c=a+b; a=b; b=c; } }


What is the code of a c program that will read in a positive integer value and determine If the integer is a prime number and If the integer is a Fibonacci number?

see the program


Program for sin series in c language?

find the program in c-pgms.blogspot.com


C orogram for Fibonacci series?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { printf("The first 20numbers of Fibonacci series are:"); int a=0, b=1, c, n=2; printf("%d \t, %d", &amp;a, &amp;b); while(n&lt;20) { c=a+b; printf("\t %d", &amp;c); a=b; b=c; n++; } getch(); }