blob: bac568839dab7cd7c3382e1a1e9347bd5a822cdc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
using System;
namespace FibonacciWorkplace
{
public class Program
{
static void Main(string[] args)
{
Console.Write("How long should the Fibonacci Series be?? ");
int lengthOfSeries = Convert.ToInt32(Console.ReadLine());
if (lengthOfSeries<=2)
{
LengthCheck(lengthOfSeries);
}
FibonacciSeries(0, 1, 1, lengthOfSeries);
Console.ReadKey();
}
public static void LengthCheck(int lengthOfSeries)
{
if (lengthOfSeries<=1)
{
Console.Write("The Fibonacci Series needs to be greater than 2");
lengthOfSeries = Convert.ToInt32(Console.ReadLine());
LengthCheck(lengthOfSeries);
}
}
public static void FibonacciSeries(int firstNumber, int secondNumber, int counter, int lengthOfSeries)
{
Console.Write(firstNumber + " ");
if (counter < lengthOfSeries)
{
int sum = firstNumber + secondNumber;
counter++;
FibonacciSeries(secondNumber, sum, counter, lengthOfSeries);
}
}
}
}
|