Advertisement
callumbinner22

task 5

Nov 6th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Enter a whole number");
  14.             uint n = uint.Parse(Console.ReadLine());
  15.  
  16.             int first = 0;
  17.             int second = 1;
  18.             int third = 0;
  19.             int sum = 0;
  20.  
  21.             for (int i = 0; i < n - 1; i++)
  22.             {
  23.                 first = second;
  24.                 second = third;
  25.                 third = first + second;
  26.                 sum = sum + third;
  27.             }
  28.             Console.WriteLine("\nsum of first {0} number in Fibonacci's sequence = {1}\n\n", n, sum);
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement