Thursday 30 August 2012

Fibonacci series in C# Program

Desciption:
This is the code fibonacci series is dispalyed. The fibonacci series is the set of values which are unique and come in certain sequence i.e. The first two values 0 and 1 are displayed as per initialization, the next successive values are diaplyed by adding the preceeding two values.
 
C# Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace codeforfibonacciseries
{
class Program
{
static void Main(string[] args)
{
int i = 0;
int j = 1;
int k = 1;
int n = 0;
int m = 0;
m = Console.Read();
m++;
Console.WriteLine("The Fibonacci series values are:");
Console.Write(" {0}, {1}", i,j);
for (n = 0; n <= m; n++)
{
k = i +j;
i = j;
j = k;
Console.Write(" {0} ", k);
}
}
}
}
Sample Output:
The Fibonacci series values are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597 ….

No comments:

Post a Comment

Please do not enter any Spam link in the Comment box

Featured post

10 Best Ways to Earn Money from Facebook

10 Best Ways to Earn Money from Facebook Facebook is a household name all over the world. The social networking platform has more than...