Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace algoHazi_09_17
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine(fakt(10));
- Console.WriteLine(fibonacci(10));
- Console.ReadLine();
- }
- static int fakt(int k)
- {
- if (k == 0) return 1;
- else
- {
- int f = 1;
- for (int i = 1; i <= k; i++)
- {
- f *= i;
- }
- return f;
- }
- }
- static int fibonacci(int n)
- {
- if (n <= 1) return n;
- else
- {
- int a = n - 1;
- int b = n - 2;
- int c = a + b;
- for (int i = 3; i <= n; i++)
- {
- Console.WriteLine(c);
- a = n - i;
- b = n - 1 - i;
- c += a + b;
- }
- return c;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement