Advertisement
wingman007

MiitItmom2023

Nov 13th, 2023 (edited)
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 20.57 KB | None | 0 0
  1. using System.Globalization;
  2. using System.Net.NetworkInformation;
  3. using System.Text;
  4.  
  5. class Progarm
  6. {
  7.     static void Main()
  8.     {
  9.         // Greet();
  10.         // See https://aka.ms/new-console-template for more information
  11.         // 1. Hello World
  12.         Console.WriteLine("Hello, World!");
  13.  
  14.         // Shortcuts Ctrl+. | Ctrl+r,r | cw \t\t | Ctrl+k,d | Ctrl+k,c | Ctrl+k,u
  15.         // 2. Primitive data types, variables, literals
  16.         byte myByte1 = 1;
  17.         byte myByte2 = 7;
  18.  
  19.         sbyte mySByte1 = -1;
  20.  
  21.         Console.WriteLine(myByte1 + myByte2);
  22.  
  23.  
  24.         // I. Types have: name (e.g. int), size, default value
  25.         // II. Variables have: name (A-Za-z_0-9 all utf-8, can't start with 0-9, can't be a keyword), type, value
  26.         // built-in types:  
  27.         //2.1. integer (default = 0)
  28.         byte myByte = 23; // unsigned 8-bis (0 to 255) default = 0
  29.         sbyte mySByte = -128; // signed 8-bit (-128 to 127) default = 0
  30.  
  31.         short myShort = -1000; // signed 16-bit (-32,768 to 32,767) default = 0
  32.         ushort myUshort = 2000;  // unsigned 16-bit (0 to 65,535) default = 0
  33.  
  34.         int myVar = 4; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
  35.         int myVar2 = 5; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
  36.         uint myUint = 12000U; // unsigned 32-bit (0 to 4, 294, 967, 295)
  37.  
  38.         int sum = myVar + myVar2; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
  39.  
  40.         sum = 0xA8F1; // hexadecimal literal
  41.         sum = 0XA8F1; // hexadecimal literal
  42.  
  43.         // Greet();
  44.  
  45.         long myLong = 42432L;// signed 64-bit (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
  46.         ulong myUlong = 23423423U; // unsigned 64-bit (0 to 18,446,744,073,709,551,615)
  47.         ulong maxIntValue = UInt64.MaxValue;
  48.         Console.WriteLine(maxIntValue); // 18446744073709551615
  49.  
  50.         // 2.2. Real (default 0.0 for F/f D/d M/m)
  51.         float myFloat = 4.566F; // signed 32-bit (±1.5e-45 to ±3.4e38) up to 7 symbols/digits
  52.         myFloat = 67.8E35f; // litteral with "E/e"
  53.  
  54.         double myDouble = 34.56d; // signed 64-bit (±5.0e-324 to ±1.7e+308) up to 15-16 symbols/digits
  55.         myDouble = -3.4e-10;
  56.  
  57.         decimal myDecimal = 23.45M; // signed 128-bit (±1.0e-28 to ±7.9e28) precission 28-29 symbols/digits, closest to 0 ±1.0e-28, decimal floating-point arithmetic
  58.  
  59.  
  60.         // Declare some variables
  61.         float floatPI = 3.141592653589793238f;
  62.         double doublePI = 3.141592653589793238;
  63.         decimal decimalPI = 3.14159265358979323846m;
  64.  
  65.         Console.WriteLine("Float PI is: " + floatPI); // Float PI is: 3.141593 only 7 digits
  66.         Console.WriteLine("Double PI is: " + doublePI); // Double PI is: 3.14159265358979  16 digits
  67.         Console.WriteLine(decimalPI); // 3.14159265358979323846
  68.  
  69.         // 2.3. Char
  70.         char myFirstLetter = 'S';
  71.         Console.WriteLine((int)myFirstLetter);
  72.  
  73.         char symbol = (char)78;
  74.         Console.WriteLine(symbol);
  75.         char myChar = '\u0065';
  76.         Console.WriteLine(myChar);
  77.  
  78.         myChar = '\uffff';
  79.         Console.WriteLine(myChar);
  80.  
  81.         myChar = '\'';
  82.  
  83.         // escaping
  84.         char myEscape = '\n'; // \n \t \r \' \\ \" \uXXXX
  85.  
  86.         // 2.4. String (default null) Reference, value in the heap. String.Compare(string1, string2) > 0 if they have to switch
  87.         string myName = "Stoyan Cheresharov";
  88.  
  89.         // 2.5. Bool (default false)
  90.         bool myBool = true; // false | true
  91.  
  92.  
  93.         Object myObject = 2;
  94.         myObject = "Stoyan";
  95.  
  96.  
  97.         // 3.
  98.         int a = 5;
  99.         int b = 4;
  100.         Console.WriteLine(a + b); // 9
  101.         Console.WriteLine(a + b++); // 9
  102.         Console.WriteLine(a + b); // 10
  103.         Console.WriteLine(a + (++b)); // 11
  104.         Console.WriteLine(a + b); // 11
  105.         Console.WriteLine(14 / a); // 2
  106.         Console.WriteLine(14 % a); // 4
  107.  
  108.         // 3.1. Arithmetic operators
  109.         a = 11;
  110.         b = 2;
  111.         // Arithmetic operators
  112.         Console.WriteLine(a + b);
  113.         Console.WriteLine(a - b);
  114.         Console.WriteLine(a / b);
  115.         Console.WriteLine(a * b);
  116.         Console.WriteLine(a++);
  117.         Console.WriteLine(a);
  118.         Console.WriteLine(++a);
  119.         Console.WriteLine(a % b);
  120.         Console.WriteLine(--a);
  121.         Console.WriteLine(a--);
  122.  
  123.         //3.2. For comparison
  124.         Console.WriteLine(a > b);
  125.         Console.WriteLine(a < b);
  126.         Console.WriteLine(a >= b);
  127.         Console.WriteLine(a <= b);
  128.         Console.WriteLine(a == b);
  129.         Console.WriteLine(a != b);
  130.  
  131.         //3.3. Logical
  132.         bool x = true;
  133.         bool y = false;
  134.  
  135.         Console.WriteLine(x && y);
  136.         Console.WriteLine(x || y);
  137.         Console.WriteLine(x ^ y);
  138.         Console.WriteLine(!x);
  139.  
  140.         //&&
  141.         //x   y   z
  142.         //0   0   0
  143.         //1   0   0
  144.         //0   1   0
  145.         //1   1   1
  146.  
  147.         // ||
  148.         //x   y   z
  149.         //0   0   0
  150.         //1   0   1
  151.         //0   1   1
  152.         //1   1   1
  153.  
  154.         // ^
  155.         //x   y   z
  156.         //0   0   0
  157.         //1   0   1
  158.         //0   1   1
  159.         //1   1   0
  160.  
  161.         // !
  162.         //x z
  163.         //0 1
  164.         //1 0
  165.  
  166.         ////3.4. for asignments
  167.         //a += 3; // a = a + 3;
  168.  
  169.         ////3.5. Bitwise operators
  170.         //Console.WriteLine(1 << 1);
  171.         //Console.WriteLine(2 >> 1);
  172.         //Console.WriteLine(1 | 2);
  173.         //Console.WriteLine(1 & 2);
  174.         //Console.WriteLine(1 ^ 3);// 2
  175.  
  176.  
  177.         //// 3.6. trinary
  178.         //int c = (a > b) ? a : b;
  179.  
  180.         //if (a > b)
  181.         //{
  182.         //    c = a;
  183.         //}
  184.         //else
  185.         //{
  186.         //    c = b;
  187.         //}
  188.  
  189.         ////int? a1 = null;
  190.         ////int? b1 = 6;
  191.         //// a1 = null;
  192.         ////int? z = a1 ?? b1;
  193.  
  194.  
  195.         /*
  196.                 // 4. Console
  197.                 Console.OutputEncoding = Encoding.UTF8;
  198.                 Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
  199.  
  200.                 Console.Write("Stoyan ");
  201.                 Console.Write("Cheresharov");
  202.                 Console.WriteLine("My name is Desi. I am {0} years old. my favorite number is {1}", 10, 3);
  203.                 Console.WriteLine("{0,10:C2} I will continue", 1234);
  204.  
  205.                 // Formatting Numbers
  206.                 // Standard Formatting Symbols C, D, E, F, N, P, X
  207.                 Console.WriteLine("{0:C2}", 123.456); //Output: 123,46 лв.
  208.                 Console.WriteLine("{0:D6}", -1234); //Output: -001234
  209.                 Console.WriteLine("{0:E2}", 123); //Output: 1,23Е+002
  210.                 Console.WriteLine("{0:F2}", -123.456); //Output: -123,46
  211.                 Console.WriteLine("{0:N2}", 1234567.8); //Output: 1 234 567,80
  212.                 Console.WriteLine("{0:P}", 0.456); //Output: 45,60 %
  213.                 Console.WriteLine("{0:X}", 254); //Output: FE
  214.  
  215.                 // Custom Formatting Symbols 0000, ###, %, E0 Е+0 Е-0
  216.                 Console.WriteLine("{0:0.00}", 1); //Output: 1,00
  217.                 Console.WriteLine("{0:#.##}", 0.234); //Output: ,23
  218.                 Console.WriteLine("{0:#####}", 12345.67); //Output: 12346
  219.                 Console.WriteLine("{0:(0#) ### ## ##}", 29342525); //Output: (02) 934 25 25
  220.                 Console.WriteLine("{0:%##}", 0.234);//Output: %23
  221.  
  222.                 //Console.ForegroundColor = ConsoleColor.DarkYellow;
  223.                 //Console.BackgroundColor = ConsoleColor.DarkBlue;
  224.                 Console.Clear();
  225.                 // Standard Formatting Symbols for DateTime
  226.                 DateTime d = DateTime.Now;
  227.  
  228.                 Console.WriteLine("{0:d}", d); // d D
  229.  
  230.                 //Console.SetCursorPosition(5, 10); // left top
  231.                 Console.WriteLine("Това е кирилица: ☺");
  232.  
  233.                 // char unicorn = '\u1F984'; ???
  234.  
  235.                 Console.Write("Please enter your age: ");
  236.  
  237.                 int age = int.Parse(Console.ReadLine());
  238.  
  239.                 string name = "Stoyan";
  240.  
  241.                 char firstLetter = name[0];
  242.  
  243.                 int number = 312321;
  244.                 string numberString = number.ToString();
  245.                 Console.WriteLine(numberString[1]);
  246.  
  247.                 // 5. Conditional Logic
  248.                 int secondNumber = 3;
  249.                 int firstNumber = 2;
  250.                 if (secondNumber > firstNumber)
  251.                 {
  252.                     Console.WriteLine("secondNumber > firstNumber");
  253.                 }
  254.  
  255.                 if (true)
  256.                 {
  257.                     Console.WriteLine("secondNumber > firstNumber");
  258.                 }
  259.                 else
  260.                 {
  261.                     Console.WriteLine("secondNumber > firstNumber");
  262.                 }
  263.  
  264.                 int myAge = 12;
  265.  
  266.                 if (myAge < 3)
  267.                 {
  268.                     Console.WriteLine("You are a baby!");
  269.                 }
  270.                 else if (3 <= myAge && myAge < 12)
  271.                 {
  272.                     Console.WriteLine("You are a kid!");
  273.                 }
  274.                 else if (12 <= myAge && myAge < 18)
  275.                 {
  276.                     Console.WriteLine("You are a teenager!");
  277.                 }
  278.                 else if (18 <= myAge && myAge < 30)
  279.                 {
  280.                     Console.WriteLine("You are in your golden age!");
  281.                 }
  282.                 else
  283.                 {
  284.                     Console.WriteLine("You are an adult");
  285.                 }
  286.  
  287.  
  288.                 char firtsLetter = 'S';
  289.                 switch (firtsLetter)
  290.                 {
  291.                     case 'A':
  292.                     case 'S':
  293.                         Console.WriteLine("Your first letter tells me you are a lucky man!");
  294.                         break;
  295.                     case 'V':
  296.                         Console.WriteLine("You are victorious!");
  297.                         break;
  298.                     default:
  299.                         Console.WriteLine("I don't know?");
  300.                         break;
  301.                 }
  302.  
  303.                 // 6. loops
  304.                 int i = 0;
  305.                 while (i < 100)
  306.                 {
  307.                     Console.WriteLine(i);
  308.                     i++;
  309.                 }
  310.  
  311.                 int number1 = 0;
  312.                 do
  313.                 {
  314.                     Console.Write("Please, enter a number between 0 and 10:");
  315.                     number1 = int.Parse(Console.ReadLine());
  316.  
  317.                 } while (number1 < 0 || number1 > 10);
  318.  
  319.                 for (i = 0; i < 100; i++)
  320.                 {
  321.                     Console.WriteLine(i);
  322.                 }
  323.  
  324.                 int[] myArray = { 1, 2, 3,};
  325.                 foreach (var item in myArray)
  326.                 {
  327.                     Console.WriteLine(item);
  328.                 }
  329.  
  330.                 Console.Write("Please, enter a character: ");
  331.                 int myChar1 = Console.Read();
  332.                 Console.WriteLine(myChar1);
  333.  
  334.                 // int lucky = 1235;
  335.                 int a1, a2, a3, a4;
  336.  
  337.                 for (int lucky = 0; lucky <= 9999; lucky++)
  338.                 {
  339.                     a1 = lucky / 1000;
  340.                     a2 = (lucky / 100) % 10;
  341.                     a3 = (lucky / 10) % 10;
  342.                     a4 = lucky % 10;
  343.  
  344.                     if (a1 + a2 == a3 + a4)
  345.                     {
  346.                         Console.WriteLine(lucky);
  347.                     }
  348.                 }
  349.         */
  350.  
  351.         Console.Clear();
  352.         // 7.
  353.         int[] ints = { 212, 22, 3, 4 };
  354.         ints[0] = 34;
  355.         Console.WriteLine(ints[0]);
  356.  
  357.         // 7.1.
  358.         int[] ints1 = new int[3];
  359.         ints1[1] = 4;
  360.  
  361.         // 7.2.
  362.         int[] ints2 = new int[3] { 32, 45, 67 };
  363.  
  364.         int lastElement = ints2[ints2.Length - 1];
  365.  
  366.         for (int i = 0; i < ints2.Length; i++)
  367.         {
  368.             Console.WriteLine(ints2[i]);
  369.         }
  370.  
  371.         int[,] matrix =
  372.         {
  373.             {32, 34, 45 },
  374.             { 56, 54, 34},
  375.             { 543, 34, 43}
  376.         };
  377.  
  378.         int[][] jagged = {
  379.             new int[] { 32, 45, 67},
  380.             new int[] {6456, 5435, 54345, 545}
  381.         };
  382.  
  383.         Console.WriteLine(jagged[1][1]);
  384.  
  385.         List<int> myList = new List<int>();
  386.         myList.Add(23);
  387.  
  388.         Dictionary<string, string> myDictionary = new Dictionary<string, string>();
  389.  
  390.         myDictionary.Add("щастлив", "happy");
  391.  
  392.         Console.WriteLine(myDictionary["щастлив"]);
  393.  
  394.         var tugay = "String";
  395.  
  396.         // var myInput = int.Parse(Console.ReadLine());
  397.  
  398.         foreach (var item in myList)
  399.         {
  400.             Console.WriteLine(item);
  401.         }
  402.  
  403.         string[] places = { "София", "пловдив" };
  404.  
  405.         int counter = 0;
  406.         for (int i = 0; i < places.Length; i++)
  407.         {
  408.             if (char.IsUpper(places[i][0]))
  409.             {
  410.                 Console.WriteLine(places[i]);
  411.                 counter++;
  412.             }
  413.         }
  414.  
  415.         Console.WriteLine("The cities with capital Letter are {0}", counter);
  416.  
  417.         Console.WriteLine("2093 to BIN {0}.", Convert.ToString(2093, 2));
  418.         Console.WriteLine("2093 to OCT {0}.", Convert.ToString(2093, 8));
  419.         Console.WriteLine("2093 to HEX {0}.", Convert.ToString(2093, 16));
  420.         Console.WriteLine("2093 In a number system with base/radix = 5 {0}.",
  421.             Convert.ToString(2093, 2));
  422.  
  423.         Console.WriteLine();
  424.  
  425.         for (int i = ints2.Length - 1; i >= 0; i--)
  426.         {
  427.             Console.WriteLine(ints2[i]);
  428.         }
  429.  
  430.         // 9. Methods
  431.         Greet(null, 1,2,23);
  432.  
  433.         //Greet(ages: 1, 23, 4, name : "Viktor" );
  434.  
  435.         int[] myArray = { 1231, 432432, 4234 };
  436.  
  437.         Console.WriteLine(GetAverage(myArray));
  438.  
  439.  
  440.         Console.WriteLine(FactorialIter(10));
  441.  
  442.         // 0! = 1
  443.         // n! = (n-1)! * n
  444.  
  445.         // 3! = 1 * 2 * 3 = 6
  446.         Console.WriteLine(FactorialRecur(10));
  447.  
  448.         //
  449.         String[] students = new String[3];
  450.         // zad 371
  451.         // a
  452.         InputStudentsNames(students);
  453.  
  454.         // b
  455.         OutputStudents(students);
  456.  
  457.         // c
  458.         String[] femailNames = GetFemaleNames(students);
  459.         OutputStudents(femailNames);
  460.  
  461.  
  462.  
  463.  
  464.         //double calc = 0;
  465.         //for (int x = 0; x < 169; x++)
  466.         //{
  467.         //    for (int y = 0; y < 256; y++)
  468.         //    {
  469.         //        calc = Math.Pow(x, 2) / 169 + Math.Pow(y, 2) / 256;
  470.         //        if (calc < 1)
  471.         //        {
  472.         //            Console.WriteLine($"The point with coordinates x = {x} y = {y} is inside the elipse");
  473.         //        }
  474.         //    }
  475.         //}
  476.  
  477.         //Console.WriteLine(DateTime.Now);
  478.  
  479.         //int x1 = 0, y1 = 0;
  480.  
  481.         //while (true)
  482.         //{
  483.         //    Console.Clear();
  484.         //    Console.SetCursorPosition(x1, y1);
  485.         //    Console.WriteLine(DateTime.Now);
  486.         //    Thread.Sleep(10);
  487.         //    x1++;
  488.         //    y1++;
  489.         //}
  490.  
  491.  
  492.         // 8.
  493.  
  494.         // IV
  495.         //VI
  496.  
  497.         //44(10)
  498.  
  499.         //4 * 10 ^ 1 + 4 * 10 ^ 0 = 40 + 4
  500.  
  501.         //44(8)
  502.  
  503.         //4 * 8 ^ 1 + 4 * 8 ^ 0 = 32 + 4 = 36
  504.  
  505.         //44(5)
  506.         //4 * 5 ^ 1 + 4 * 5 ^ 0 = 20 + 4 = 24
  507.  
  508.         //44
  509.  
  510.         //44 : 2 = 22 | 0
  511.         //22 : 2 = 11 | 0
  512.         //11 : 2 = 5 | 1
  513.         //5 : 2 = 2 | 1
  514.         //2 : 2 = 1 | 0
  515.         //            1
  516.  
  517.         //101100(2) = 44(10)
  518.  
  519.  
  520.         //0010 1100
  521.  
  522.         //2C
  523.  
  524.         //8421
  525.  
  526.         //101 100
  527.         //5    4
  528.  
  529.         //54()
  530.  
  531.         //23.45
  532.  
  533.         //23 : 2 = 11 | 1
  534.         //11 : 2 = 5 | 1
  535.         //5 : 2 = 2 | 1
  536.         //2 : 2 = 1 | 0
  537.  
  538.         //        1
  539.  
  540.         //10111.011
  541.  
  542.         //1.0111011 * 2 ^ 4
  543.  
  544.         //.45 * 2 = 0.9 | 0
  545.         //0.9 * 2 = 0.8 | 1
  546.         //0.8 * 2 = 0.6 | 1
  547.  
  548.         //123.56 => 1,23.56 * 10 ^ 2
  549.  
  550.  
  551.         //number = 346
  552.         //(r ^ n - 1) - number
  553.  
  554.         //(10 ^ 3 - 1) - 346 =
  555.         //999
  556.         //-
  557.         //346
  558.         //---- -
  559.         //653
  560.  
  561.         //9999999999
  562.         //-
  563.         //4332423532
  564.         //----------------
  565.         //5667...
  566.  
  567.  
  568.         //1111111111111
  569.         //-
  570.         //1010101111111
  571.         //------------------
  572.         //0101010000000
  573.  
  574.         //(r ^ n - 1) - number
  575.         //(r ^ n) - number
  576.  
  577.  
  578.         //7 - 3 = 4
  579.  
  580.         //7 + 7 = 1 | 4
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.         /*
  588.  
  589.         // ------ in a nutshell -----
  590.  
  591.         //a += 3; // a = a + 3;
  592.  
  593.         //// essentials
  594.         //// 4.
  595.         //Console.WriteLine();
  596.         //string name = Console.ReadLine();
  597.         //double n = double.Parse(Console.ReadLine());
  598.  
  599.         //// 5. Conditional logic
  600.         //// 5.1.
  601.         //if (a > 5)
  602.         //{
  603.         //    Console.WriteLine("a > 5");
  604.         //}
  605.  
  606.         //if (a > 5)
  607.         //{
  608.         //    Console.WriteLine("a > 5");
  609.         //}
  610.         //else
  611.         //{
  612.         //    Console.WriteLine("a < 5");
  613.         //}
  614.  
  615.         //Console.WriteLine("Please enter your age: ");
  616.         //int age = int.Parse(Console.ReadLine());
  617.         //if (age > 0 && age <= 3)
  618.         //{
  619.         //    Console.WriteLine("You are a baby");
  620.         //}
  621.         //else if (age > 3 && age <= 12)
  622.         //{
  623.         //    Console.WriteLine("You are a kid");
  624.         //}
  625.         //else if (age > 12 && age <= 18)
  626.         //{
  627.         //    Console.WriteLine("You are a teenager");
  628.         //}
  629.         //else
  630.         //{
  631.         //    Console.WriteLine("You are an adult");
  632.         //}
  633.  
  634.  
  635.         //char firstLetter = Char.Parse(Console.ReadLine());
  636.         //switch (firstLetter)
  637.         //{
  638.         //    case 'A':
  639.         //    case 'N':
  640.         //        Console.WriteLine("Maybe your name is Nilyay");
  641.         //        break;
  642.         //    default:
  643.         //        Console.WriteLine("I don't know");
  644.         //        break;
  645.         //}
  646.  
  647.  
  648.         //// 6. Loops
  649.  
  650.         //int i = 0;
  651.         //while (i < 100)
  652.         //{
  653.         //    Console.WriteLine(i);
  654.         //    i++;
  655.         //}
  656.  
  657.  
  658.         //do
  659.         //{
  660.         //    Console.WriteLine("Please enter your age: ");
  661.         //    age = int.Parse(Console.ReadLine());
  662.         //} while (age < 0 && age > 120);
  663.  
  664.  
  665.  
  666.         //for (i = 0; i < 100; i++)
  667.         //{
  668.         //    Console.WriteLine(i);
  669.         //}
  670.         Greet("Nilyay");
  671.         int[] ages = new int[10];
  672.         ages[0] = 18;
  673.         ages[5] = 17;
  674.  
  675.         foreach (int item in ages)
  676.         {
  677.             Console.WriteLine(item);
  678.         }
  679.  
  680.         Greet("Magi");
  681.  
  682.  
  683.         int number = 5698;
  684.         int a1 = number / 1000;
  685.         int a2 = (number / 100) % 10;
  686.         int a3 = (number / 10) % 10;
  687.         int a4 = number % 10;
  688.  
  689.         Console.WriteLine("The number in reverse is {0}{1}{2}{3}", a4, a3, a2, a1);
  690.     }
  691.  
  692.     static void Greet(string name = "Megan")
  693.     {
  694.         Console.WriteLine("Hello" + name);
  695.     }
  696.  
  697.     static int CalculateSum(int a, int b)
  698.     {
  699.         return a + b;
  700.     }
  701.  
  702.     */
  703.  
  704.     }
  705.  
  706.     static void Greet(String name = "Viktor", params int[] ages)
  707.     {
  708.         Console.WriteLine($"Hello {name}");
  709.         foreach (var item in ages)
  710.         {
  711.             Console.WriteLine(item);
  712.         }
  713.     }
  714.  
  715.     static double GetAverage(int[] n)
  716.     {
  717.         double average = 0;
  718.         int sum = 0;
  719.         foreach (var item in n)
  720.         {
  721.             sum += item;
  722.         }
  723.         if (n.Length != 0) average = sum / n.Length;
  724.         return average;
  725.     }
  726.  
  727.     static int FactorialIter(int n)
  728.     {
  729.         int mul = 1;
  730.         for (int i = 1; i <= n; i++)
  731.         {
  732.             mul *= i;
  733.         }
  734.         return mul;
  735.     }
  736.  
  737.     // 0! = 1
  738.     // n! = (n-1)! * n
  739.     static int FactorialRecur(int n)
  740.     {
  741.         if (n == 0) return 1;
  742.         return FactorialRecur(n - 1) * n;
  743.     }
  744.  
  745.     static void InputStudentsNames(String[] names)
  746.     {
  747.         for (int i = 0; i < names.Length; i++)
  748.         {
  749.             Console.Write("Please, enter the name (first, middle, family) of {0}:", i);
  750.             names[i] = Console.ReadLine();
  751.         }
  752.     }
  753.  
  754.     static void OutputStudents(String[] students)
  755.     {
  756.         for (int i = 0; i < students.Length; i++)
  757.         {
  758.             Console.WriteLine("Student number {0} = {1}", i, students[i]);
  759.         }
  760.     }
  761.  
  762.     static String[] GetFemaleNames(String[] students)
  763.     {
  764.         String[] femaleNames = new String[students.Length];
  765.         int counter = 0;
  766.         for (int i = 0; i < students.Length; i++)
  767.         {
  768.             if (students[i][students.Length - 1] == 'а')
  769.             {
  770.                 femaleNames[counter] = students[i];
  771.                 counter++;
  772.             }
  773.         }
  774.         return femaleNames;
  775.     }
  776.  
  777.  
  778. }
  779.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement