Large Fibonacci Numbers in C#

CsharpProgrammingServer Side Programming

To display large Fibonacci numbers, try the following login and code.

Here, we have set the value of n as the series. Set it to get the Fibonacci number. Below, we have set it to 100 to get the first 100 Fibonacci numbers.

Since the first two numbers in a Fibonacci series are 0 and 1. Therefore, we will set the first two values.

int val1 = 0, val2 = 1;

The following is the complete code to display large Fibonacci numbers.

Example

 Live Demo

using System;
public class Demo {
   public static void Main(string[] args) {
      int val1 = 0, val2 = 1, val3, i, n;
      n = 40;
      Console.WriteLine("Displaying Fibonacci series:");
      Console.Write(val1+" "+val2+" ");
      for(i=2;i<n;++i) {
         val3 = val1 + val2;
         Console.Write(val3+"");
         val1 = val2;
         val2 = val3;
      }
   }
}


raja
Published on 20-Aug-2018 13:04:38
Advertisements