Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- class SequenceOfFibonacci
- {
- static void Main()
- {
- /* Write a program that reads a number N and calculates the sum of the first N members of the sequence of Fibonacci:
- * 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, … */
- Console.WriteLine("Enter number of members that you want to sum");
- int n = int.Parse(Console.ReadLine());
- BigInteger numOne = 0;
- BigInteger numTwo = 1;
- BigInteger nextNum;
- BigInteger sum = 0;
- for (int i = 0; i <= n-2;i++)
- {
- nextNum = numOne + numTwo;
- numOne = numTwo;
- numTwo = nextNum;
- sum += numOne;
- }
- Console.WriteLine("The sum of first {0} members of sequence of Fibonacci is {1}", n, sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement