Advertisement
wingman007

Task373

Nov 3rd, 2020 (edited)
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.33 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Task373
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             // 1.
  10.             int[] array = new int[70];
  11.             GenerateRandomNumbers(array, 0, 201);
  12.             PrintNotZero(array);
  13.  
  14.             // 2.
  15.             int[] arrayMul = new int[10];
  16.             InputIntArray(arrayMul);
  17.             Console.WriteLine(MultInInterval(arrayMul, 10, 20));
  18.  
  19.             // 3.
  20.             Console.Write("Please, enter integer unsigned a = ");
  21.             byte a = byte.Parse(Console.ReadLine());
  22.  
  23.             Console.Write("Please, enter integer unsigned b = ");
  24.             byte b = byte.Parse(Console.ReadLine());
  25.  
  26.             Console.Write("Please, enter integer unsigned c = ");
  27.             byte c = byte.Parse(Console.ReadLine());
  28.  
  29.             // Console.WriteLine(Sum(a) + Sum(b)*Sum(c));
  30.  
  31.             Console.WriteLine(Sum(a) + Sum(b*c));
  32.  
  33.  
  34.             int number = 874;
  35.             int firstDigit = number / 100;
  36.             Console.Write(PrintTextDigit(firstDigit) + "стотин");
  37.  
  38.             int secondDigit = (number % 100) / 10;
  39.             Console.Write(" " + PrintTextDigit(secondDigit) + "десет");
  40.  
  41.             int thirdDigit = number % 10;
  42.             Console.Write(" и " + PrintTextDigit(thirdDigit));
  43.  
  44.             // Sum the add numbers for end type 0
  45.             //int input = 0;
  46.             //int sum = 0;
  47.             //do
  48.             //{
  49.             //    Console.Write("Please, enter the next number (type 0 for end): ");
  50.             //    input = int.Parse(Console.ReadLine());
  51.             //    if (input % 2 == 1)
  52.             //    {
  53.             //        sum += input;
  54.             //    }
  55.  
  56.             //} while (input != 0);
  57.  
  58.             //Console.WriteLine(sum);
  59.  
  60.         }
  61.  
  62.         public static void GenerateRandomNumbers(int[] array, int min, int max)
  63.         {
  64.             Random randomGen = new Random();
  65.             for (int i = 0; i < array.Length; i++)
  66.             {
  67.                 array[i] = randomGen.Next(min, max);
  68.             }
  69.         }
  70.  
  71.         public static void PrintNotZero(int[] array)
  72.         {
  73.             for (int i = 0; i < array.Length; i++)
  74.             {
  75.                 if (array[i] != 0) Console.WriteLine("arra[{0}] = {1}", i, array[i]);
  76.             }
  77.         }
  78.  
  79.         public static void InputIntArray(int[] array)
  80.         {
  81.             for (int i = 0; i < array.Length; i++)
  82.             {
  83.                 Console.Write("Please, eneter array[{0}] = ", i);
  84.                 array[i] = int.Parse(Console.ReadLine());
  85.             }
  86.         }
  87.  
  88.         public static int MultInInterval(int[] array, int min, int max)
  89.         {
  90.             int mul = 1;
  91.             for (int i = 0; i < array.Length; i++)
  92.             {
  93.                 if (array[i] >= min && array[i] <= max)
  94.                 {
  95.                     mul *= array[i];
  96.                 }
  97.             }
  98.             return mul;
  99.         }
  100.  
  101.         public static ulong Sum(byte k)
  102.         {
  103.             int[] array = new int[k];
  104.             Random randGen = new Random();
  105.             ulong sum = 0;
  106.             for (int i = 0; i < array.Length; i++)
  107.             {
  108.                 array[i] = randGen.Next();
  109.                 if (array[i] % 2 == 0)
  110.                 {
  111.                     sum += (ulong)array[i];
  112.                 }
  113.             }
  114.             return sum;
  115.         }
  116.  
  117.         public static string PrintTextDigit(int digit)
  118.         {
  119.             switch (digit)
  120.             {
  121.                 case 0:
  122.                     return "Нула";
  123.                 case 1:
  124.                     return "Едно";
  125.                     break;
  126.                 case 2:
  127.                     return  "Две";
  128.                     break;
  129.                 case 3:
  130.                     return  "Три";
  131.                     break;
  132.                 case 4:
  133.                     return  "Четири";
  134.                     break;
  135.                 case 5:
  136.                     return  "Пет";
  137.                     break;
  138.                 case 6:
  139.                     return "Шест";
  140.                     break;
  141.                 case 7:
  142.                     return "Седем";
  143.                     break;
  144.                 case 8:
  145.                     return "Осем";
  146.                     break;
  147.                 case 9:
  148.                     return "Девет";
  149.                     break;
  150.                 default:
  151.                     return "";
  152.             }
  153.         }
  154.  
  155.  
  156.         // Sum of a sequence of math expressions
  157.         public static double CalcMultiplication(int n)
  158.         {
  159.             double sum = 0;
  160.             for (int i = 2; i <= n; i++)
  161.             {
  162.                 sum += 1 / (Math.Pow(i,2) - (i-1) + 1);
  163.             }
  164.             return sum;
  165.         }
  166.  
  167.         // Generate random numbers find mul of only 2 digit numbers the last digit 5
  168.         public static int Sss(int k)
  169.         {
  170.             int mul = 1;
  171.             Random randomGen = new Random();
  172.             int[] array = new int[k];
  173.             for (int i = 0; i < array.Length; i++)
  174.             {
  175.                 array[i] = randomGen.Next();
  176.                 if (array[i] > 9 && array[i] < 100 && array[i] % 10 == 5)
  177.                 {
  178.                     mul *= array[i];
  179.                 }
  180.             }
  181.             return mul;
  182.         }
  183.  
  184.  
  185.     }
  186. }
  187.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement