Friday, 22 November 2013

PHP : Fibonacci Code

Fibonacci Series :

$a = 0;
$b = 1;
$term = 7;
$i = 0;

echo $a." ".$b." ";
for($i; $i < $term -1 ; $i++)
{
$c = $b +$a;
echo $c." ";
$a = $b;
$b = $c;
}

Output :

1
1
2
3
5
8
13

To know about the Fibonacci Series in detail and also to know the codes of the Fibonacci Series in various other programming languages Click Here

If the above link doesn't work go to this URL :

Thursday, 21 November 2013

Fibonacci Series


About the Fibonacci Series :

The Fibonacci series of numbers are found by adding the two numbers before it.

         0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

We can compute Fibonacci numbers with recursion. This can be a bit slow. It is also possible to use iteration in computing Fibonacci Series.To compute a Fibonacci number at a certain position N, we have to loop through all previous numbers starting at position 0.

Logic :                                                                                                                                                        
prevnextsum
shifted to prevshifted to next
112
123
235
358
5813
813...
13......

Applications :

  1. Financial Markets
  2. Natural Phenomena
  3. Music , etc .,

Fibonacci Codes in various programming languages :

RUBY : Fibonacci Series

Fibonacci Series :

Here is the Fibonacci Series for the Ruby code :

def  fibonacci(n)
    n1,n2=0,1
    while n1 <=n
         print “#{n1}\n”
        n1,n2=n2,n1+n2
    end
end
fibonacci(7)

Output :

1
1
2
3
5
8
13


To know about the Fibonacci Series in detail and also to know the codes of the Fibonacci Series in various other programming languages Click Here

If the above link doesn't work go to this URL :
http://gappcode.blogspot.in/2013/11/fibonacci-series.html

JAVASCRIPT : Fibonacci Series

Fibonacci Series :


The following code describes about the Fibonacci series implemented in JavaScript with the JavaScript code implemented inside the HTML Tags :

<html>
<body>
<script type="text/javascript">
var a=0,b=1,c;
document.write("Fibonacci");
while (b<=7)
{
c=a+b;
a=b;
b=c;
document.write(c);
document.write("<br/>");
}
</script>
</body>
</html>

Output :

1
1
2
3
5
8
13


To know about the Fibonacci Series in detail and also to know the codes of the Fibonacci Series in various other programming languages Click Here

If the above link doesn't work go to this URL :
http://gappcode.blogspot.in/2013/11/fibonacci-series.html

JAVA : Fibonacci Series

Fibnacci Series :

Here is the Java code for the Fibonacci Series :
class Fibonacci
{
 public static void main(String args[])
 {  
  int prev, next, sum, n;
  prev=next=1
  for(n=1;n<=7;n++)
  {
   System.out.println(prev);
   sum=prev+next;
   prev=next;
   next=sum;
  }
 }
}

Output :

1
1
2
3
5
8
13


To know about the Fibonacci Series in detail and also to know the codes of the Fibonacci Series in various other programming languages Click Here

If the above link doesn't work go to this URL :
http://gappcode.blogspot.in/2013/11/fibonacci-series.html

PYTHON : Fibonacci Series

FIBONACCI SERIES :


Here is the python code for the Fibonacci series :

# Defining Functions
def fib(n):    # write Fibonacci series up to n
    """Print a Fibonacci series up to n."""
    a, b = 0, 1
    while b < n:
        print b,
        a, b = b, a+b
 
# Now call the function we just defined:
fib(7)

Output :

1 1 2 3 5 8 13
To know about the Fibonacci Series in detail and also to know the codes of the Fibonacci Series in various other programming languages Click Here

If the above link doesn't work go to this URL :
http://gappcode.blogspot.in/2013/11/fibonacci-series.html


Wednesday, 20 November 2013

C# : Fibonacci Code

The below code gives the Fibonacci series of numbers in C# for n number of terms :
using System;
class Program
{
    public static int Fibonacci(int n)
    {
 int a = 0;
 int b = 1;
 // In N steps compute Fibonacci sequence iteratively.
 for (int i = 0; i < n; i++)
 {
     int temp = a;
     a = b;
     b = temp + b;
 }
 return a;
    }

    static void Main()
    {
 for (int i = 0; i < 15; i++)
 {
     Console.WriteLine(Fibonacci(i));
 }
    }
}

Output :

1 1 2 3 5 8 13

To know about the Fibonacci Series in detail and also to know the codes of the Fibonacci Series in various other programming languages Click Here
If the above link doesn't work go to this URL :
http://gappcode.blogspot.in/2013/11/fibonacci-series.html