IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
CAdvanced Functions : Recursive Fibonacci
<06.14>
#include <stdio.h> int fibonacci (int n) { int ans; if (n == 1 || n == 2) ans = 1; else ans = fibonacci(n - 2) + fibonacci(n - 1); return (ans); } int main (void) { int a, result; printf ("Enter an integer number: "); scanf ("%d", &a); /* calling the function */ result = fibonacci (a); if (a == 1) printf ("The %dst fibonacci number is %d.\n", a, result); if (a == 2) printf ("The %dnd fibonacci number is %d.\n", a, result); if (a == 3) printf ("The %drd fibonacci number is %d.\n", a, result); if (a > 3) printf ("The %dth fibonacci number is %d.\n", a, result); return (0); }
Hergestellt in Deutschland / Made in Germany
Enter an integer number: 10 The 10th fibonacci number is 55.
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland