Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- long long ciag (int n) {
- if (n==1) return 0;
- if (n==2) return 1;
- if (n>2) return (ciag(n-1)) + (ciag(n-2));
- }
- int main () {
- int n;
- cout<<"Podaj liczbe: ";
- cin>>n;
- cout<<"Wartosc w ciagu Fibonacciego dla "<<n<<"-tej liczby to: "<<ciag(n)<<endl;
- return 0;
- }
- -------------------------------------------------------------------------------------
- #include <iostream>
- using namespace std;
- void ciag (int n) {
- long long a=0, b=1;
- for (int i=1; i<n; i++) {
- b += a;
- a = b-a;
- }
- cout<<a;
- }
- int main () {
- int n;
- cout<<"Podaj pozycje w ciagu: ";
- cin>>n;
- cout<<"Wartosc w ciagu dla "<<n<<" jest: ";
- ciag(n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement