Advertisement
vencinachev

Day3SimpleRecursions

Sep 5th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Recursions
  4. {
  5.     class Program
  6.     {
  7.         static int gcd(int a, int b)
  8.         {
  9.             if (b == 0)
  10.             {
  11.                 return a;
  12.             }
  13.             return gcd(b, a % b);
  14.         }
  15.  
  16.         static int lcm(int a, int b)
  17.         {
  18.             return ((a * b) / gcd(a, b));
  19.         }
  20.  
  21.         static void CountDown(int num)
  22.         {
  23.             if (num == 0)
  24.             {
  25.                 return;
  26.             }
  27.  
  28.             Console.WriteLine(num);
  29.             CountDown(num - 1);
  30.  
  31.         }
  32.  
  33.         static void PrintDigits(int num)
  34.         {
  35.             if (num == 0)
  36.             {
  37.                 return;
  38.             }
  39.             PrintDigits(num / 10);
  40.             Console.Write(num % 10 + " ");
  41.         }
  42.         static decimal Factorial(int n)
  43.         {
  44.             if (n < 0)
  45.             {
  46.                 throw new ArgumentException("Factroial is not defined for negative numbers!");
  47.             }
  48.             if (n == 0)
  49.             {
  50.                 return 1;
  51.             }
  52.  
  53.             return n * Factorial(n - 1);
  54.         }
  55.  
  56.         static decimal FactorialI(int n)
  57.         {
  58.             decimal result = 1;
  59.             for (int i = 1; i <= n; i++)
  60.             {
  61.                 result *= i;
  62.             }
  63.             return result;
  64.         }
  65.  
  66.         static long Fib(int n)
  67.         {
  68.             if (n <= 2)
  69.             {
  70.                 return 1;
  71.             }
  72.             return Fib(n - 2) + Fib(n - 2);
  73.         }
  74.  
  75.         static void PrintMirrorTriangles(int n)
  76.         {
  77.             if (n == 0)
  78.             {
  79.                 return;
  80.             }
  81.             Console.WriteLine(new string('*', n));
  82.             PrintMirrorTriangles(n - 1);
  83.             Console.WriteLine(new string('#', n));
  84.         }
  85.         static void Main(string[] args)
  86.         {
  87.            
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement