using System.Collections.Generic;
using System.Linq;
namespace MainPrograms
{
public class Program
{
public static void Main(string[] args)
{
// 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());
//Declaring an Array where we will store our fibonacci series
double[] fibonacci=new double[1000];
//Initializing our fibnacci series with two intial fibonacci values
fibonacci[0] = 0;
fibonacci[1] = 1;
// This for loop controls the number of fibonacci series elements
for (int i = 2; i < Target; i++)
{
fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2];
}
//This for loop is for printing our fibonacci series
for (int i = 0; i < Target; i++)
{
Console.WriteLine("{0}", fibonacci[i]);
}
Console.ReadLine();
}
}
}
No comments:
Post a Comment