Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. int main7() //iteracyjnie  
  2. {
  3.     int wyraz;
  4.     cout << "Podaj ktory wyraz ciagu fibonacciego chcesz obliczyc: ";
  5.     cin >> wyraz;
  6.     if (wyraz <= 2)
  7.         cout << "Jest to 1" << endl;
  8.     else
  9.     {
  10.         long long f1 = 1;
  11.         long long f2 = 1;
  12.         long long temp;
  13.         int x = 0;
  14.         for (int i = 3; i <= wyraz; i++)
  15.         {
  16.             x++;
  17.             temp = f1 + f2;
  18.             f1 = f2;
  19.             f2 = temp;
  20.         }
  21.         cout << "Jest to wartosc: " << f2 << endl;
  22.         cout <<"Aby obliczyć " << wyraz << "potrzebujemy " <<x << " ruchow" << endl;
  23.     }
  24.     return 0;
  25. }
  26. long long fibonnaci(long long i) //rekurencyjnie
  27. {
  28.     y++;
  29.     if (i == 0)
  30.         return 0;
  31.     else if (i == 1)
  32.         return 1;
  33.     else
  34.         return fibonnaci(i - 1) + fibonnaci(i - 2);
  35. }
  36.  
  37. int silnia(int n) //rekurencyjnie
  38. {
  39.     z++;
  40.     if (n == 0)
  41.         return 1;
  42.     else
  43.         return n*silnia(n - 1);
  44. }
  45.  
  46. int main() //iteracyjnie
  47. {
  48.     int x = 0;
  49.     int wyraz;
  50.     cout << "Podaj ktory wyraz silni chcesz obliczyc: ";
  51.     cin >> wyraz;
  52.     if (wyraz <= 1)
  53.         cout << "Jest to 1" << endl;
  54.     else
  55.     {
  56.         long long silnia = 1;
  57.         for (int i = 1; i <= wyraz; i++)
  58.         {
  59.             x++;
  60.             silnia = silnia*i;
  61.         }
  62.         cout << "Jest to wartosc: " << silnia << endl;
  63.         cout << "Aby obliczyć " << wyraz << "potrzebujemy " << x << " ruchow" << endl;
  64.     }
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement