#include <iostream>

struct Cvor{
   long long int element;
    Cvor *veza;
};

Cvor *KreirajFibonaccijevuListu(int n){
    Cvor *pocetak{}, *prethodni;

    long long int f1 = 1, f2 = 1;
    
    for(int i = 0; i < n; i++){

        long long int f;
        if(i==0 || i == 1) f = 1;
        else{
            f = f1 + f2;
            f1 = f2;
            f2 = f;
        }
        Cvor *novi = new Cvor {f, nullptr};
        

        if(!pocetak) pocetak = novi;
        else prethodni->veza = novi;

        prethodni = novi;
    }

    return pocetak;
}

int BrojParnihElemenata(Cvor *pocetak){
    int parni = 0;
    for(auto p = pocetak; p != nullptr; p = p->veza){
        if(p->element % 2 == 0) parni++;
    }
    return parni;
}
void UnistiListu(Cvor *pocetak){
    Cvor *sljedeci;
    for(auto p = pocetak; p != nullptr; p = sljedeci){
        sljedeci = p->veza;
        delete p;
    }
}







int main() {
    std::cout << "Unesite n: ";
    int n;
    std::cin >> n;
    Cvor *Fibonaci = KreirajFibonaccijevuListu(n);
    std::cout << "Broj parnih: "<<BrojParnihElemenata(Fibonaci);
    UnistiListu(Fibonaci);
    
    
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: