Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Program to find nth term of fibonacci series in C#

  1. using System;
  2. namespace ForgetCode
  3. {
  4. public class MainClass
  5. {
  6. public static void Main()
  7. {
  8. int x = 0, y = 1, z=0, nth, i;
  9. Console.WriteLine("\n\nPlease Enter The Term Number:");
  10. nth = Convert.ToInt32(Console.ReadLine());
  11. for (i = 1; i <= nth; i++)
  12. {
  13. z = x + y;
  14. x = y;
  15. y = z;
  16. }
  17.  
  18. Console.WriteLine("\nthe {0}th term of Fibonacci Series is is {1}\n\n\n", nth, z);
  19.  
  20. }
  21.  
  22. }
  23. }

Output:
Please Enter The Term Number:
5
the 5th term of Fibonacci Series is is 8