Home » .Net

Define Fibonacci series - Write a program to print fibonacci series in c#

Learn: What is fibonacci series? Write a program in C#.Net that will print the fibonacci series till defined number of times.

To understand the program of fibonacci series, first we should understand the concept of 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.

Consider the program:

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

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).






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.