Sunday, August 23, 2015

C# Program to Generate Fibonacci Series

This C# Program generates Fibonacci series.The numbers that precedes the series are 0 and 1.The next number is found by adding up the two numbers before it. Here is source code of the C# program which generates a Fibonacci series.The C# program is successfully compiled and executed with Microsoft Visual Studio.The program output is also shown below.
  1. /*
  2.  * C#  Program to Generate Fibonacci Series
  3.  */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8.  
  9. namespace fibonaci
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             int i, count, f1 = 0, f2 = 1, f3 = 0;
  16.             Console.Write("Enter the Limit : ");
  17.             count = int.Parse(Console.ReadLine());
  18.             Console.WriteLine(f1);
  19.             Console.WriteLine(f2);
  20.             for (i = 0; i <= count; i++)
  21.             {
  22.                 f3 = f1 + f2;
  23.                 Console.WriteLine(f3);
  24.                 f1 = f2;
  25.                 f2 = f3;
  26.             }
  27.             Console.ReadLine();
  28.  
  29.         }
  30.     }
  31. }
     
     
    Here is the output of the C# Program:
    
    
    
    Enter the Limit : 10
    0
    1
    1
    2
    3
    5
    8
    13
    21
    34
    55
    89
    144
     

No comments:

Post a Comment