top of page

Exercitii de informatica folosind sirul lui Fibonacci

/*
Verificare daca un numar n este termen din  sirrul lui Fibbo .
*/
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int a1=0 , a2=1 , n , k=0 , aux ;
    cout<<"Introduceti numarul :";
    cin>>n;
    if(n==0||n==1)
        cout<<"Este termen"<<endl;
    else
        while(n>=a2)
        {
            if(n==a2)
            {
                k=1;
                break;
            }
            aux=a2;
            a2=a1+a2;
            a1=aux;
        }
    if(k==1)
        cout<<"Este termen"<<endl;
    else
        cout<<"Nu este termen"<<endl;
    return 0;
}

bottom of page