Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <limits.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- using namespace std;
- int fibonacci(int n)
- {
- int a;
- int b;
- int c;
- if((n==1)||(n==0))
- {
- return(n);
- }
- else
- {
- c=fibonacci(n-2);
- b=fibonacci(n-1);
- a=b+c;
- if (a<b||a<=c){
- return 0;
- system("pause");
- }
- return a;
- }
- }
- int main(int argc, char** argv) {
- int n,i=0;
- int fib;
- cout<<"Ile liczb fibonacciego mam wypisac? ";
- cin>>n;
- cout<<"Liczby :"<<endl;
- while(i<n||(fib!=0 &&i !=0))
- {
- fib=fibonacci(i);
- cout<<i+1<<". ";
- cout<<fib<<endl;
- i++;
- }
- cout<<" ERROR : WARTOSC WYKRACZA POZA INTEGERA"<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement