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...

Martial Arts

Hello Everyone,   Martial arts is form of combat used for different reasons like Self-Defense, staying fit, entertainment, military purposes and for spirituality reasons as well. Although, China is famous for martial arts in the late 20th century, but was famous in Europe in 1550's. It basically originated from eastern Asia in the early 6000 BC.   Some different formats of Martial Arts to consider are: Military Martial Arts      Military practices both armed and unarmed Martial Arts for the emergency situations. It is mostly practiced by the paramilitary forces, so that they can survive even without weapons in severe conditions like that of a war. It is useful for law enforcement applications. Health & Fitness       Martial Arts is a very good exercise for your health. It keeps you in a well form. t keeps you active. It also maintains your fitness. Some people practice it for spirituality like 'Tai Chi' especially in No...

How to avoid criticism?

     Have you ever felt demotivated and discouraged when someone talks shit about your favorite sports, team, nation, or anything else which you are attached to? If yes, then you need to consider the followings. First off, there are two types of criticism, constructive criticism and destructive criticism. Constructive criticism helps you to become a better person and destructive criticism is only meant to hurt and demoralize you. Constructive criticism     As mentioned above, constructive criticism helps you become a better person, it is meant to tell you the harsh realities about you or anything else you like. Your teacher, good friends and parents criticize you constructively to become a better person for tomorrow. This type of criticism may be in a harsh tone and a soft tone as well. The person who criticizes you telling the realities about you or anything you like is not meant to demoralize you. Dealing with constructive criticism   ...