Pages

Showing posts with label series. Show all posts
Showing posts with label series. Show all posts

Friday, April 11, 2014

C program to find Fibonacci Series with understanding logic

Fibonacci Series or Sequence
The Fibonacci numbers or Fibonacci series or Fibonacci sequence has first two numbers equal to 1 and 0 and the further each number is consist of the addition of previous two numbers
  1st number = 0
  2nd number = 1
  3rd number = 0+1= 1
  4th number = 1+1= 2
  5th number = 1+2= 3
  And so on.  

 The Fibonacci Sequence can be written as  0,1,1,2,3,5,8,13........



 C++ program to find Fibonacci Series upto given range.This C++ program use simple logic to get the about of writing code in C++ for Fibonacci Series
  1.     #include<iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.        int range, first = 0, second = 1, fibonicci=0;
  6.        cout << "Enter Range for Terms of Fibonacci Sequence: ";
  7.        cin >> range;
  8.        cout << "Fibonicci Series upto " << range << " Terms "<< endl;
  9.        for ( int c = 0 ; c < range ; c++ )
  10.        {
  11.           if ( c <= 1 )
  12.              fibonicci = c;
  13.           else
  14.           {
  15.              fibonicci = first + second;
  16.              first = second;
  17.              second = fibonicci;
  18.           }
  19.           cout << fibonicci <<" ";
  20.        }
  21.        return 0;
  22.     }

  Fibonacci Series program logic explanation
  • Before writing C++ code we understand that what is Fibonacci Series and in what sequence numbers are occurs
  • After understanding mathematically Fibonacci series completely we thought it in the form of C++ code
  • The Fibonacci series is infinite but we cant make a program that display an infinite output
  • In above program we take input the range in integer upto which Fibonacci series will be displayed
  • For this purpose a for loop has been taken which starts from 0 and terminates less than range for example if Input is 5 then for loop will run from 0 to 4.
  • In for loop if  variable c is  less or equal than 1 in this case if statement  will be executed  and if  c is greater than 1 else part will be executed for greater than 1
   e.g if range=2 than only
   if part will run.   let input is equal to 5
   Before loop variables values


   first = 0, second = 1, Fibonacci=0;
   After input range=5
   Values are changing in the following sequence
   in below table  c   representing the for loop iterations
   c    first    second   Fibonacci    Output
  

   0     0         1                 0           0 

   1     0         1                 1           0 1
  
   2     0         1           0+1=1         0 1 1
        
          1          1                1           

   3     1         1           1+1=2         0 1 1 2
     
          1         2                  2

   4    1         2             1+2=3         0 1 1 2 3  its final output
   
         2         3                  3      


     

Image View Of  Program (Click on Image To Enlarge)
Fibonacci series in C++ image Code

Fibonacci Series In C++ Programming
Fibonacci series C++ Code


If you have any queries comment below.
Read More..

Thursday, March 27, 2014

A series of puzzles Posters of the USSR part 7


A series of puzzles
A series of puzzles "Posters of the USSR." part 7
This informative series of puzzles dedicated posters produced in the USSR. The game has three difficulty levels. 16, 25 and 36 puzzles. The game has several raskadnov each level, so that every time the game will be a new and interesting. The same account provided moves.

Серия пазлов «Плакаты СССР». Часть 7
Это познавательная серия пятнашек, посвященная плакатам, выпущенным в СССР. В игре три уровня сложности. 16, 25 и 36 пазлов. В игре предусмотрен несколько раскаднов каждого из уровней, так что каждый раз игра будет новой и интересной. Так же предусмотрен счет ходов. A series of puzzles "Posters of the USSR." part 7
This informative series of puzzles dedicated posters produced in the USSR. The game has three difficulty levels. 16, 25 and 36 puzzles. The game has several raskadnov each level, so that every time the game will be a new and interesting. The same account provided moves.

Серия пазлов «Плакаты СССР». Часть 7
Это познавательная серия пятнашек, посвященная плакатам, выпущенным в СССР. В игре три уровня сложности. 16, 25 и 36 пазлов. В игре предусмотрен несколько раскаднов каждого из уровней, так что каждый раз игра будет новой и интересной. Так же предусмотрен счет ходов.

Read More..