Users Online

· Guests Online: 87

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

Fibonacci Series Program in C#

Fibonacci Series Program in C#

 

This is a C# Program to generate fibonacci series.

Problem Description

This C# Program generates Fibonacci series.

Problem Solution

The numbers that precedes the series are 0 and 1. The next number is found by adding up the two numbers before it.

Program/Source Code

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.

/*
 * C#  Program to Generate Fibonacci Series
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace fibonaci
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, count, f1 = 0, f2 = 1, f3 = 0;
            Console.Write("Enter the Limit : ");
            count = int.Parse(Console.ReadLine());
            Console.WriteLine(f1);
            Console.WriteLine(f2);
            for (i = 0; i <= count; i++)
            {
                f3 = f1 + f2;
                Console.WriteLine(f3);
                f1 = f2;
                f2 = f3;
            }
            Console.ReadLine();
 
        }
    }
}
Program Explanation

In this C# program, we are reading the limit to generate the Fibonacci series using ‘count’ variable. The numbers that precede the series are 0 and 1. The next number is found by adding up the two numbers before it. Using for loop generate Fibonacci series.

 

Initialize the value of ‘i’ variable as 0 and check the condition that the value of ‘i’ variable is less than or equal to the value of ‘count’ variable. Compute the summation of the value of ‘f1’ variable with the value of ‘f2’ variable. Print the Fibonacci series of the value.

Runtime Test Cases
 
Enter the Limit : 10
0
1
1
2
3
5
8
13
21
34
55
89
144

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.70 seconds
10,829,729 unique visits