Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6.  
  7. class Fibonacci
  8. {
  9.     static void Main()
  10.     {
  11.         int[] x = new int[5000];
  12.        
  13.         int y;
  14.         int i = 2;
  15.         int sum = 0;
  16.         System.Console.WriteLine("請輸入第N個Fibonacci數 N = 0~5000之間");
  17.         y = Convert.ToInt32(Console.ReadLine());
  18.  
  19.         for (; i < y; i++)
  20.         {
  21.             x[0] = 0;
  22.             x[1] = 1;
  23.             x[i] = x[i - 1]+ x[i - 2];
  24.             sum = x[i];
  25.         }
  26.         System.Console.WriteLine("第{0}個數是:{1}", y,sum);
  27.  
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement