Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Напишете програма, която чете от конзолата числото N и отпечатва
- сумата на първите N члена от редицата на Фибоначи: 0, 1, 1, 2, 3, 5,
- 8, 13, 21, 34, 55, 89, 144, 233, 377, ...*/
- using System;
- class SumOfFibonacci
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int a1 = 0;
- int a2 = 1;
- int sum = 0;
- for (int i = 1; i < n; i++)
- {
- int an = a1 + a2;
- sum += a2;
- a1 = a2;
- a2 = an;
- }
- Console.WriteLine(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement