Fibonacci series in C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace FibonacciSeriesInCSharp
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int i, nOne = 0, nTwo = 1, next;
  13.             Console.WriteLine(“Enter a Number”);
  14.             int n = Convert.ToInt32(Console.ReadLine());
  15.             Console.WriteLine(“Fibonacci Series are”);
  16.             for (i = 0; i < n; i++)
  17.             {
  18.                 if (i<=1)
  19.                 {
  20.                     next = i;
  21.                 }
  22.                 else
  23.                 {
  24.                     next = nOne + nTwo;
  25.                     nOne = nTwo;
  26.                     nTwo = next;
  27.                 }
  28.                 Console.WriteLine(next);
  29.             }
  30.             Console.ReadLine();
  31.         }
  32.     }
  33. }

Download Code

Advertisements
Categories: Math-Snippets | Leave a comment

Post navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.