C# program to enter number and print fibonacci series upto that nth number.

Rajesh_Kumar
Posted by Rajesh_Kumar under C# category on | Points: 40 | Views : 9299
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

Comments or Responses

Login to post response