Skip to main content

C++ program to implement Fibanocci series by recursion (Example for function recursion)


#include<iostream.h>
#include<conio.h>
int fib(int);
int main()
{
    int n;
    int f=0,s=1;
    cout<<"Enter the range";
    cin>>n;
    cout<<"fibanocci series... ";
    cout<<f<<"\t"<<s;
    for (int i=2;i<n;i++)
    cout<<"\t"<<fib(i);
    getch();
}

int fib(int n)
{
    if(n==1 || n==0)
    {
            return n;
    }
    else
    {
        return (fib(n-1)+fib(n-2));
    }
       
}
Output ==>

Comments

Popular posts from this blog

Java Tutorial Part 5

Keywords Keywords are the predefined words in a program,we can't alter the meaning of keywords. Ex:- for,do,if,class,public. There are almost 62 keywords are in java Identifiers Which is used to give name for a variable or class or methods. Rules for a valid identifier are, *identifiers name must need to begin with an alphabet not by a number.(i.e. 1name is invalid name1 is valid) *Keywords will not be an identifier *Case sensitive, upper case and lower case are treated differently (if you have a variable HELLO and hello, system will treat both in differently)

Basic Computer Shortcuts

Ctrl+C : Copies selected content. Ctrl+V : Pastes copied content Ctrl+X : Cut's selected content Ctrl+Z : undo the previous action Ctrl+Y : redo the action you undid Ctrl+A : Selects whole content Ctrl+P : print Windows Logo key( )+Down Arrow : Minimizes the window. Windows Logo key( )+Up Arrow : Maximizes the window. Windows Logo key( )+Left/Right Arrow : To compare two windows. While pressing the Windows logo key  , click the Right Arrow key or the Left Arrow key and your browser will slide over to one side. Select another window (such as a Word document) and use the shortcut only with the opposite arrow. Windows Logo key( )+L  : Locks your computer Windows Logo key( )+P : Presentation display mode Windows Logo key( )+Plus(+)/Minus(-)  : Zoom In and Zoom Out Windows Logo key( )+F : Search for a file Windows Logo key( )+F1 : help Ctrl+Shift+Esc : To open Task Manager

JAVA Tutorial Part 1

Part 1 ,we are discussing about basic programming concepts. Java is a general purpose object oriented programming language. There are few technical terms in the first sentence, it might be difficult to understand for a beginner's ,right  here I can explain the basic terms. Program -Series of instructions (Code) to perform a particular task. And Collection of program's are referred to a Software Language's you know it very well, which using for communication. Here computer Language's are classified into 2 category's, they are Machine Language or Low level language and High Level Language Machine Language - Which is the one and only language, a computer can understood directly and this is binary itself either 0 or 1.Simply we can say computer could understood binary language only. Programming instructions written by using a natural language(English) is termed as High level language . Example for the high level language's are Java,C,C++,PHP,ASP...