Guest User

Godzio

a guest
Oct 27th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. /*
  2.  * Zadanie 3
  3.  * Ten program implementuje ciag fibonacciego.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. typedef unsigned long int ul;
  10.  
  11. ul fib (int n) {
  12.     /*
  13.      * Ta funkcja zwraca n-ta liczbe fibonacciego. Nie potrzebujemy
  14.      * super wydajnosci, wiec posluzymy sie definicja rekurencyjna.
  15.      */
  16.     if (n==0)
  17.         return 0;
  18.     if (n==1)
  19.         return 1;
  20.    
  21.     return fib(n-1) + fib(n-2);
  22. }
  23.  
  24. int main (void) {
  25.     int i; 
  26.     printf("fib(10) = %lu\n", fib(10));
  27.    
  28.     for (i=0; fib(i)<15000 ; i++); 
  29.     printf("Nierownosc fib(n) > 15 000 jest spelniona juz dla n=%d!\n", i);
  30.    
  31.     return EXIT_SUCCESS;
  32. }
  33.  
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment