Advertisement
wingman007

RecursionIntroProgramming2018

Nov 26th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.90 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3. using System.Text;
  4.  
  5. namespace ConsoleApp3a
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             //BigInteger bInt
  12.             Console.OutputEncoding = Encoding.UTF8;
  13.             Console.WriteLine("Hello World!");
  14.  
  15.             Console.WriteLine(SayTheDigit(3));
  16.             Console.WriteLine(IsPointIn(1.2, 2.3, 10));
  17.  
  18.             // 0!= 1;
  19.             // n! = (n-1)! *n;
  20.             // 10
  21.             int factorial = 0;
  22.             for (int i = 0; i < 10; i++)
  23.             {
  24.                 if (i == 0)
  25.                 {
  26.                     factorial = 1;
  27.                 }
  28.                 else
  29.                 {
  30.                     factorial *= i;
  31.                 }              
  32.             }
  33.  
  34.             Console.WriteLine("10! = {0}", factorial);
  35.             Console.WriteLine(Factorial(10));
  36.  
  37.             // 1,1,2,3,5,8,13,21,34
  38.             Console.WriteLine(Fibonacci(40));
  39.  
  40.             //for (int i = 0; i < 5; i++)
  41.             //{
  42.             //    Console.Write("{0}, ", Fibonacci(i));
  43.             //}
  44.  
  45.             Console.Write("Please enter a = ");
  46.             double a = double.Parse(Console.ReadLine());
  47.             Console.WriteLine();
  48.  
  49.             Console.Write("Please enter b = ");
  50.             double b = double.Parse(Console.ReadLine());
  51.             Console.WriteLine();
  52.  
  53.             Console.Write("Please enter c  = ");
  54.             double c = double.Parse(Console.ReadLine());
  55.             Console.WriteLine();
  56.  
  57.  
  58.             Console.WriteLine("Is existing? - {0}.", CheckTriangleExists(a,b,c));
  59.             if (CheckTriangleExists(a, b, c)) {
  60.                 Console.WriteLine("The surface is: {0}", CalculateSurface(a, b, c));
  61.             }
  62.         }
  63.  
  64.         static double InputSite(string nameVariable) {
  65.             Console.Write($"Please enter {nameVariable} = ");
  66.             return  double.Parse(Console.ReadLine());
  67.             // Console.WriteLine();
  68.         }
  69.  
  70.         static bool CheckTriangleExists(double a, double b, double c)
  71.         {
  72.             bool isExists = false;
  73.             if (a < b + c && b < c + a && c < b + a) isExists = true;
  74.             // return (a < b + c && b < c + a && c < b + a);
  75.             return isExists;
  76.         }
  77.  
  78.         static double CalculateSurface(double a, double b, double c) {
  79.             double perimeter = a + b + c;
  80.             return Math.Sqrt(perimeter * (perimeter - a) * (perimeter - b) * (perimeter - c));
  81.         }
  82.  
  83.         static int Factorial(int n)
  84.         {
  85.             if (n == 0) return 1; // 0!= 1;
  86.             return Factorial(n - 1) * n; // n! = (n-1)! *n;
  87.         }
  88.  
  89.         static int Fibonacci(int number)
  90.         {
  91.             if (number == 1 || number == 2) return 1;
  92.             return Fibonacci(number - 1) + Fibonacci(number - 2);
  93.         }
  94.  
  95.         static bool IsPointIn(double x, double y, double r)
  96.         {
  97.             bool isIn = false;
  98.             double d = Math.Sqrt(Math.Pow((x - 1), 2) + Math.Pow((y - 0), 2));
  99.  
  100.             isIn = d > r;
  101.  
  102.             return isIn;
  103.         }
  104.  
  105.         static string SayTheDigit(int digit) {
  106.             string digitName = "";
  107.             switch (digit)
  108.             {
  109.                 case 1:
  110.                     digitName = "едно";
  111.                     break;
  112.                 case 2:
  113.                     digitName = "две";
  114.                     break;
  115.                 case 3:
  116.                     digitName = "три";
  117.                     break;
  118.                 case 4:
  119.                     digitName = "четири";
  120.                     break;
  121.                 case 5:
  122.                     digitName = "пет";
  123.                     break;
  124.                 case 6:
  125.                     digitName = "шест";
  126.                     break;
  127.  
  128.                 default:
  129.                     break;
  130.             }
  131.             return digitName;
  132.         }
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement