Program for Fibonacci Series in c#

Posted by Jeenal under C# on 12/23/2013 | Points: 10 | Views : 1556 | Status : [Member] | Replies : 2
Hi friends,wanted to share with you all the fibonacci program in C# in simple and easy way


// C# program to enter number and print fibonacci series upto that nth number
using System;
class Program
{
static void Main(string[] args)
{
int n, first = 0, second = 1, third = 0;
Console.Write("Enter a number : ");
n = Convert.ToInt32(Console.ReadLine());
Console.Write("First {0} Fibonacci numbers {1} {2} ",n, first, second);
for (int i = 3; i <= n; i++)
{
third = first + second;
Console.Write("{0} ", third);
first = second;
second = third;
}
}
}

Output
Enter a number : 10
First 10 Fibonacci numbers : 0 1 1 2 3 5 8 13 21 34

Enter a number : 5
First 5 Fibonacci numbers : 0 1 1 2 3

As i am a beginner i got to learn from the online free tutorials with online compiler with easy solution on cbtsam.com




Responses

Posted by: vishalneeraj-24503 on: 12/23/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi friend,it's not aa right place to post code,article.

it's only for posting question related to Dot net.

Please post article or code in artical section or code section.

Jeenal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mack.Richards18 on: 1/21/2014 [Member] Starter | Points: 25

Up
0
Down
I agree with Vishal@Neeraj this is not the right place. But the code you have pasted is very useful.
People always curious about the various technique to solve Fibonacci Series.

Jeenal, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response