fibonacci series in c# program

fibonacci series using for loop in c# program

Hello everyone, I am going to share the code sample for the fibonacci series using c# with console application as given below.


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

namespace ConsoleApplication1
{
    public class FibonacciSeries
    {
        public static int fiboSeries(int n)
        {
            int pre_no = -1;
            int next_no = 1;
            for (int i = 0; i < n; i++)
            {
                int sum = next_no + pre_no;
                pre_no = next_no;
                next_no = sum;
                Console.WriteLine(next_no);
            }
            return next_no;
        }

        static void Main(string[] a)
        {
            int number;
            Console.WriteLine("Enter the number.");
            number = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("\n");
            Console.WriteLine("First " + number + " numbers in the series are equals to ");
            fiboSeries(number);
            Console.Read();
        }
    }
}


OutPut as given below


ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.