HI WELCOME TO SIRIS

C# program to print fibonacci series

Leave a Comment
A prime number is not divisible by any other number apart from 1 and itself. So, we use this logic in this program to determine if a number is prime.


using System;

namespace SamplePrograms{    class FibonacciSeries    {        public static void Main()        {            // Prompt the user to enter their target number            Console.WriteLine("How many numbers do you want in the fibonacci series");

            // Read the user input from console and convert to integer            int Target = int.Parse(Console.ReadLine());

            // Create integer variables to hold previous and next numbers            int PreviousNumber = -1, NextNumber = 1;

            // This for loop controls the number of fibonacci series elements            for (int i = 0; i < Target; i++)            {                // Logic to compute fibonacci series numbers                int Sum = PreviousNumber + NextNumber;                 PreviousNumber = NextNumber;                NextNumber = Sum;                Console.Write(NextNumber + "  ");            }

            Console.ReadLine();        }    }}
A prime number is not divisible by any other number apart from 1 and itself. So, we use this logic in this program to determine if a number is prime.

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.