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