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

Who am I? What am I doing? Why am I alive?

Have you ever wondered, what if you were left alone in the world with all the luxuries, but no people? How does it feel?  I guess I will be happy at first, and after enjoying every possible luxurious event, I'll have no one to share it with, leaving me sad and depressed (it's the worst I can imagine).  Have you ever felt lonely in a crowd? I guess, always, when you don't know anyone truly.  Why does it happen? What do we need to do?  It happens because we aren't connected with ourselves, we need some self-assessment to overcome this loneliness.   When something is bothering you or making you feel worthless, and you seek advice, people will tell you to distract yourself and find the activities that you like, but we cannot do it if we are not connected with ourselves and it takes a lot of work, a lot of self-realization, it's a process of knowing ourselves, who we truly are.  We ought to connect with our emotions and try to control them, otherwise, they ...

What do Pakistanis think about The West

Hello Everyone,                    As you know there are two sides of a coin, so there are diverse opinions about The West in Pakistanis views. Some Pakistanis think of them to be super-humans and think that there are no better people than "Gora's" ( Westerns ) and others hate them thinking that they have a huge deficiency of  Moral values. One side of the coin People of the West-  Pixabay               The people who think westerns to be super-humans also think that there is an exception of corruption in the west, which, you know is a false concept. Some extremists of this type think of the westerns to be super-honest. They make them their ideals, follow them and try to be them. Well that's not all, they are also criticized by their elders who think The West to be violators of moral values and human rights. The people who think west to be their ideal are young and mostly teenagers...

5 horrifying facts about North Korean Army

As you may have heard about North Korea and the conditions that people live in, but you may not have heard about the North Korean Army. So lets find out what is uncommon in the North Korean Army. Army-  Pixabay     Yes, you heard that right. Army Service is compulsory for everyone, Wow. There are 47 active soldiers for every 1000 people, that would be 1,190,000 active soldiers and 6,300,000 reservants, which makes it the largest army on the planet, US has 5 active soldiers for 1000, Russia 5, India 1, China 2, Pakistan 4. A common male has to serve Army for 10 years and female, 7 years. If you don't want to the job, you will be forced. A very few people can get a bachelor's degree and are still forced to serve 5 years in military. The important scientists serve 3 years in the Army. Their paramilitary force include teenagers    Teenagers from 15-18 years old are sent to The Workers-Peasant Red Guard for 15 days training in Summer to prepare th...