-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacci.cs
More file actions
48 lines (38 loc) · 978 Bytes
/
Fibonacci.cs
File metadata and controls
48 lines (38 loc) · 978 Bytes
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
42
43
44
45
46
47
48
using System;
public static class Fibonacci
{
public static int getnthFibonacci(int n)
{
if (n == 2)
{
return 1;
}
if (n == 1)
{
return 0;
}
return getnthFibonacci(n - 2) + getnthFibonacci(n - 1);
}
public static void PrintFibonacciSeries(int n)
{
int f1 = 0, f2 = 1, i;
if (n < 1)
return;
Console.Write(f1 + " ");
for (i = 1; i < n; i++)
{
Console.Write(f2 + " ");
int next = f1 + f2;
f1 = f2;
f2 = next;
}
}
public static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The {0}th Fibonacci number is {1} ", n, getnthFibonacci(n));
Console.WriteLine("The Series is :");
PrintFibonacciSeries(n);
Console.ReadKey();
}
}