Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Recursions
- {
- class Program
- {
- static uint Factorial(uint n)
- {
- if (n == 0)
- {
- return 1;
- }
- return n * Factorial(n - 1);
- }
- static void PrintToN(int n)
- {
- if (n == -1)
- {
- return;
- }
- PrintToN(n - 1);
- Console.WriteLine(n);
- }
- static void Triangle(int n)
- {
- if (n == 0)
- {
- return;
- }
- Console.WriteLine(new string('*', n));
- Triangle(n - 1);
- Console.WriteLine(new string('*', n));
- }
- static double Power(double a, int n)
- {
- if (n == 0)
- {
- return 1;
- }
- if (n < 0)
- {
- return 1 / Power(a, -n);
- }
- return a * Power(a, n - 1);
- }
- static double FastExpo(double a, int n)
- {
- if (n == 0)
- {
- return 1;
- }
- if (n < 0)
- {
- return 1 / Power(a, -n);
- }
- if (n % 2 == 0)
- {
- double res = FastExpo(a, n / 2);
- return res * res;
- }
- double res = FastExpo(a, (n - 1) / 2);
- return a * res * res;
- }
- static void Hanoi(int count, char start, char mid, char end)
- {
- if (count == 1)
- {
- Console.WriteLine($"{start}->{end}");
- return;
- }
- Hanoi(count - 1, start, end, mid);
- Hanoi(1, start, mid, end);
- Hanoi(count - 1, mid, start, end);
- }
- static void Main(string[] args)
- {
- Hanoi(4, 'A', 'B', 'C');
- //Triangle(10);
- //Console.WriteLine(FastExpo(2, 40));
- /*uint num = uint.Parse(Console.ReadLine());
- uint result = Factorial(num);
- Console.WriteLine(result);*/
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement