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;
- using System.Threading.Tasks;
- namespace Recursion
- {
- class Program
- {
- static long Factorial(long n)
- {
- if (n == 0)
- {
- return 1; // дъно
- }
- return Factorial(n - 1) * n;
- }
- static void OneToN(int n)
- {
- if (n == 0)
- {
- return; // дъно
- }
- OneToN(n - 1);
- Console.WriteLine(n);
- }
- static void NToOne(int n)
- {
- if (n == 0)
- {
- return; // дъно
- }
- Console.WriteLine(n);
- OneToN(n - 1);
- }
- static void Triangle(int n)
- {
- if (n == 0)
- {
- return;
- }
- Console.WriteLine(new string('*', n));
- Triangle(n - 1);
- Console.WriteLine(new string('*', n));
- }
- static int Fib(int n)
- {
- if (n == 1 || n == 2)
- {
- return 1;
- }
- return Fib(n - 2) + Fib(n - 1);
- }
- static double Power(double a, int n)
- {
- if (n == 0)
- {
- return 1;
- }
- if (n < 0)
- {
- return 1 / Power(a, -n);
- }
- return Power(a, n - 1) * a;
- }
- static void Main(string[] args)
- {
- Console.WriteLine(Power(2, 0));
- Console.WriteLine(Fib(6));
- Triangle(10);
- //OneToN(10);
- // Console.WriteLine(Factorial(5)); // 1 * 2 * 3 * 4 * 5 = 120
- // Console.WriteLine(Factorial(6)); // 720
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement