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

Saturday, December 24, 2011

C Program to Generate Fibonacci Series

It is a sample c program to generate a Fibonacci series.

Program Source Code


#include"stdio.h"
#include"conio.h"
void main()
{
int a , b , c , i=1;
clrscr();
a=0;
b=1;
printf(“Fibonacci Series”);
printf(“%d\n”, a);
printf(“%d\n”, b);
while(i<=10)
{
c=a+b;
printf(“%d”, c);
a=b;
b=c;
i++;
}
getch();
}

Output


Generate Fibonacci Series Output

Saturday, November 19, 2011

Find Fibonacci Series Using Recursion in C Programming

It is sample C program which demonstrate how to use recursion concept in c programming. Here is a recursion program which accept a number from user and generate Fibonacci series using recursion.

Program Code
//Find Fibonacci Series Using Recursion in C Programming
#include"stdio.h"
#include"conio.h"
fibonacci(int n);
void main()
{
 int n,r,i;
 clrscr();
 printf("********** Fibonacci Series Using Recursion *********\n");
 printf("enter a number: ");
 scanf("%d",&n);
 printf("\n\n");

 for(i=0;i<=n;i++)
 {
  r=fibonacci(i);
  printf("\t%d",r);
 }
 getch();
}

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






Saturday, November 12, 2011

PL/SQL program to generate Fibonacci series

It is a sample example of generate fibonacci series upto 10 numbers.

Aim - PL/SQL program to generate Fibonacci series.



PLSQL Sample Program: -

declare
f1 number(3);
f2 number(3);
f3 number(3);
num number(3);
begin
f1:=0;
f2:=1;
f3:=0;
num:=1;
while num<=10
loop
dbms_output.put_line(f3);
f1 :=f2;
f2:=f3;
f3:=f1+f2;
num:=num+1;
end loop;
end;




Output of PL SQL Block: -
0
1
1
2
3
5
8
13
21
34

Sunday, November 28, 2010

C Program For Fibonacci Series

Hello everybody I want to discuss about How to generate a Fibonacci series in C programming.

What is Fibonacci Series?


The first two Fibonacci numbers are 0 and 1 then next number is addition of previous two numbers.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89.....
In mathematics it is defined by recurrence relation.

Program Code


  


//C Program for generate Fibonacci series
#include "stdio.h"
#include "conio.h"
void main()
{
int a,b,c,i,n;
clrscr();
a=0;
b=1;
printf("\n enter n for how many times generate series");
scanf("%d",&n);
printf("\n FIBONACCI SERIES\n");
printf("\t%d\t%d",a,b);
for(i=0;i<n;i++)
{
c=a+b;
a=b;
b=c;
printf("\t%d",c);
}
getch();
}

Input\Output