April 2013 - Coding Bot

# Inheritance And Its Types In C++

The basic meaning of Inheritance is using a pre-defined code. This is the main advantage in Object oriented Programming (OOPS), where one can use a code that has been previously written and defined but with the condition that the code is used as-is or in other words, we are not changing the code.
All the pre-defined code is used resides into classes. To use those codes, we use a feature called inheritance, whereby, we "inherit" those classes.
The class from which other class inherits is called as Parent or Base Class and the class that inherits is called as Child or Derived Class.

# C Program To Generate Fibonacci Series

Hi Friends,
Today, we'll learn how to generate a Fibonacci Series using C. The program and concept are pretty simple. But before that, let me tell you what exactly is a Fibonacci series.  Fibonacci series is a special series in which the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. By going this way, the series generated will be:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 and so on...

The program is very simple.

First input is taken from the user that tells how many terms of the Fibonacci series will be generated and then as described above, a function is called in a loop to add the previous two numbers and generate the next number in the series.

### Here is the C Code for Fibonacci Series:

```/* Double-Click To Select Code */

#include<stdio.h>
#include<conio.h>

int fib(int n)
{
if(n==1||n==2)
return 1;

else
return(fib(n-1)+fib(n-2));
}

void main()
{
int i,n;
clrscr();
printf("Enter the number of terms: ");
scanf("%d",&n);

printf("\nThe Series is : \n\n0");

for(i=1;i<n;i++)
{
printf("%5d",fib(i)); // fib Function Called
}
getch();
}```

### Output:

Please Comment If You Liked This Post !!