Question 5 - 15th Term in Fibonacci Series

 avatar
itsLu
c_cpp
2 months ago
334 B
17
Indexable
Never
// 5. Write a program to print term 15 from the series 1, 1, 2, 3, 5
#include <iostream>
using namespace std;

int main ()
{
    int x = 1, y = 1, temp;
    for (int k = 2 ; k < 15 ; k++)
    {
        temp = x;
        x = y;
        y = temp;
        y += x; //or y = x + y;
    }
    cout << "15th Term = " << y;
}
Leave a Comment