Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Recursion
- {
- class Program
- {
- static int Fact(int n)
- {
- if (n == 0)
- {
- return 1;
- }
- return Fact(n - 1) * n;
- }
- static void PrintNumbers(int n)
- {
- if (n == 0)
- {
- return;
- }
- Console.Write($"{n} ");
- PrintNumbers(n - 1);
- Console.Write($"{n} ");
- }
- static void DrawTriangle(int n)
- {
- if (n == 0)
- {
- return;
- }
- Console.WriteLine(new string('*', n));
- DrawTriangle(n - 1);
- Console.WriteLine(new string('*', n));
- }
- static double Power(double a, int n)
- {
- if (n == 0)
- {
- return 1;
- }
- return a * Power(a, n - 1);
- }
- static double FastPower(double a, int n)
- {
- if (n == 0)
- {
- return 1;
- }
- else if (n % 2 == 0)
- {
- double x = FastPower(a, n / 2);
- return x * x;
- }
- else
- {
- return a * FastPower(a, n - 1);
- }
- }
- static void Main(string[] args)
- {
- Console.WriteLine(FastPower(1, 100000));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement