Last active
July 24, 2021 08:34
-
-
Save yhstvhd/a43c8dd077478a674c631b6c166c19e7 to your computer and use it in GitHub Desktop.
フィボナッチ数列を再帰で
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Fibonacci | |
{ | |
class Program | |
{ | |
//フィボナッチ数列を再帰処理 | |
static void Main(string[] args) | |
{ | |
int x = 10; | |
Console.WriteLine(Fibonacci(10)); | |
} | |
public static int Fibonacci(int x) | |
{ | |
if (x < 2) | |
return x; | |
else | |
return Fibonacci(x - 1) + Fibonacci(x - 2); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment