Skip to main content

C++ Program for Fibonacci series

Fibonacci Series

  Such a series in which the sum of two preceding numbers is the next number i.e 1 1 2 3 5 8 13 21.....
Following is the logic for Fibonacci series.....

#include<iostream>
using namespace std;
void main()
{
int n, t1 = 0, t2 = 1, nextTerm = 0;
cout << "Enter the number of terms: \n";
cin >> n;
cout << "Fibonacci Series: \n";
for (int i = 1; i <= n; ++i)
{
if (i == 1)
{
cout << t1 << " ";
continue;
}
if (i == 2)
{
cout << t2 << " ";
continue;
}
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
cout << nextTerm << " ";
}
system("pause");
}

Comments

Popular posts from this blog

CEME NUST, another aspect of story....

    There has been a rise in the controversy that the students of the College of Electrical and Mechanical Engineering, NUST are not treated nicely. However, I can assure that there is no other institution in Pakistan which can provide a healthy and grooming environment for the freshmen. They may provide you the advanced technology labs and buildings, but as a matter of fact, they will not train you for your better tomorrow as CEME does.      I am a student of CEME, and most importantly the most junior DE-40 in the CEME. I am against any of the rumors trying to damage the reputation of CEME, NUST. We are taught to be better persons for our society, we are taught to speak in front of public, we are taught to take responsibilities, we are taught to deal with the things calmly, we are taught to respect our elders and peers, we are taught to make decision quickly and precisely, we are taught to lead our life in a disciplined way.     As far as tha...

Imran Khan sends best wishes and prayers to the victims of flood in Kerala, India

        Imran Khan is the most different prime minister of Pakistan, has always shown patriotism for his motherland, love, and affection to the poor and needy. Lamenting on what has happened in Kerala, India, Imran Khan tweeted that he and his countrymen send their best wishes and prayers for the victims of the flood and they might provide the humanitarian assistance if needed.  Imran Khan's tweet . Imran Khan- By Heinrich Böll Stiftung from Berlin, Deutschland        445 deaths were estimated in the flood, 15 people were missing and almost a million evacuated. The property damage was estimated to be the US $3 billion. 35 out of 54 dams were opened for the first time in Indian history. All 14 districts of the Kerala state were in a state of red alert. The Indian government declared it the Level 3 Calamity, Calamity of severe nature. The capacity of dams was full and overflowed. Flood- Pixabay         It w...

Mushkpuri Diaries

        What else can be better than having fun with friends? A long awaited morning came. We were done with the OHTs, it was exhausting. Who likes exams?               A good turned evil friend of mine, kicked me out of the bed when it was 5 on the clock and I was like WTF. We reached the bus stop at 6. OK, forget about the time, we were in the Bus and we even had breakfast in the Bus. We were about to leave the boundaries of College of Electrical and Mechanical Engineering, NUST (CEME, NUST).             There were 5 Buses, we were in a great number and it was our first trip from CEME, NUST to Mushkpuri top.  4 seniors came in our Bus, afterwards. The term Senior, is often terrifying to some, but we had a lot of fun with them.         When the journey started, our beloved Class Representative (CR) started making crazy faces and moves to entertain us, but we are g...