C# Program to Print Fibonacci Series

The Fibonacci sequence is a sequence where the next number is the sum of the previous two numbers. The first two numbers of fibonacci series are 0 and 1.

C# Fibonacci Series up to n terms

``` private static void Main(string[] args)
{
int i, num, num1 = 0, num2 = 1;
int nextNum = num1 + num2;

Console.WriteLine("Enter the number of terms: ");
num = int.Parse(Console.ReadLine());

Console.Write("Fibonacci Series: {0}, {1}, ", num1, num2);

// print 3rd to nth terms
for (i = 3; i <= num; ++i)
{
Console.Write("{0}, ", nextNum);
num1 = num2;
num2 = nextNum;
nextNum = num1 + num2;
}
Console.ReadLine();
}
```

Output:

C# Fibonacci Series Up to nth Number

``` private static void Main(string[] args)
{
int num, num1 = 0, num2 = 1;
int nextNum = num1 + num2;

Console.WriteLine("Enter the number: ");
num = int.Parse(Console.ReadLine());

Console.Write("Fibonacci Series: {0}, {1}, ", num1, num2);
while (nextNum <= num)
{
Console.Write("{0}, ", nextNum);
num1 = num2;
num2 = nextNum;
nextNum = num1 + num2;
}
Console.ReadLine();
}
```

Output:

 You might also like: 1)  C# Program to Check Whether a Number is Even or Odd 2)  C# Program to print Number Triangle 3)  C# Program to Check Leap Year 4)  C# Program to Convert a List to a comma separated string 5)  C# Program to print odd numbers from 1 to N
Best quality Asp .Net Ajax Control Toolkit tutorials.

Give your valuable comments.

Name
Email
Comment
5 + 2 =

 Jquery JSON Add,Edit,Update,Delete in Asp .Net 75 Important queries in SQL Server every developer should know Dropdownlist example in asp .net 12 beautiful HTML table examples for beginners to practice 3 Different ways to add AjaxControlToolkit in Asp .Net Website. Style GridView and Pager with custom css in simple steps Gridview insert update delete in asp net CustomValidator Example in asp .net Styling asp .net login control with custom css and html ListView Edit,Update,Delete in Asp .net using Ado .net
 Set Row and Alternate Row Color in ASP.NET GridView Add row to Asp.Net GridView All ASP.NET GridView Events Explained for Beginners Difference between Gridview and Repeater in Asp.Net Change the selected value of Asp.Net DropDownList with jQuery Working with Templates in GridView: Templates example in GridView Responsive GridView Example in ASP.Net Asp.Net Button example to redirect to another page Adding checkbox column to Asp.Net GridView with code example Hide a column in GridView and still access its value
About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2024
50+ C# Programs for beginners to practice