C# - Print Fibonacci Series Program

Given first two terms (numbers), we have to print Fibonacci series using C# program.
[Last updated : March 19, 2023]

To understand the program of fibonacci series, first we should understand the concept of fibonacci series.

What is a Fibonacci Series?

Fibonacci series is a series of numbers that contains numbers of sum of last two numbers in series. Number starts from 0, 1 in Fibonacci series.

For example:

0,1,1,2,3,5,8,13,21 and so on.

In this program, we will read an integer number and check whether it is Palindrome or not. To check palindrome, we will find its reverse number and then compare if reverse of a number if equal to its value (actual number) or not, if reverse and numbers are same then given number will be palindrome.

C# program to print Fibonacci series

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    
    class Program
    {
        static void Main(string[] args)
        {
            int a = 0;
            int b = 1;
            int c = 0;
            int i = 0;

            Console.Write(a + ", " + b );

            for (i = 1; i < 10; i++)
            {
                c = a + b;
                Console.Write(", "+c);

                a = b;
                b = c;
            }

            Console.WriteLine();

        }
    }
}

Output

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55

Explanation

In this program, we are taking two integer numbers 0 and 1 initially, program will add them and print third element as 1 (which is sum of 0 and 1) and then program will sum last two elements and print next element 2 (which is sum of 1 and 1) and so on… Here we are printing fibonacci series till 10 terms (10 elements).

C# Basic Programs »


Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.