Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main7() //iteracyjnie
- {
- int wyraz;
- cout << "Podaj ktory wyraz ciagu fibonacciego chcesz obliczyc: ";
- cin >> wyraz;
- if (wyraz <= 2)
- cout << "Jest to 1" << endl;
- else
- {
- long long f1 = 1;
- long long f2 = 1;
- long long temp;
- int x = 0;
- for (int i = 3; i <= wyraz; i++)
- {
- x++;
- temp = f1 + f2;
- f1 = f2;
- f2 = temp;
- }
- cout << "Jest to wartosc: " << f2 << endl;
- cout <<"Aby obliczyć " << wyraz << "potrzebujemy " <<x << " ruchow" << endl;
- }
- return 0;
- }
- long long fibonnaci(long long i) //rekurencyjnie
- {
- y++;
- if (i == 0)
- return 0;
- else if (i == 1)
- return 1;
- else
- return fibonnaci(i - 1) + fibonnaci(i - 2);
- }
- int silnia(int n) //rekurencyjnie
- {
- z++;
- if (n == 0)
- return 1;
- else
- return n*silnia(n - 1);
- }
- int main() //iteracyjnie
- {
- int x = 0;
- int wyraz;
- cout << "Podaj ktory wyraz silni chcesz obliczyc: ";
- cin >> wyraz;
- if (wyraz <= 1)
- cout << "Jest to 1" << endl;
- else
- {
- long long silnia = 1;
- for (int i = 1; i <= wyraz; i++)
- {
- x++;
- silnia = silnia*i;
- }
- cout << "Jest to wartosc: " << silnia << endl;
- cout << "Aby obliczyć " << wyraz << "potrzebujemy " << x << " ruchow" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement