Advertisement
wingman007

Task374

Nov 10th, 2020 (edited)
922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.74 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Task374
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             /* Generate random numbers between 375 and 423
  10.             Random randomGen = new Random();
  11.             for (int i = 0; i < 130; i++)
  12.             {
  13.                var number = randomGen.Next(375, 423);
  14.                if (number == 394) continue;
  15.                 Console.WriteLine(number);
  16.             }
  17.             return;
  18.             */
  19.             Console.Write("Please, enter k = ");
  20.             int k = int.Parse(Console.ReadLine());
  21.  
  22.             Console.WriteLine("The sum of not null numbers is: {0}", InputNumbers());
  23.  
  24.             //2.
  25.             int[] array4Mul = new int[10];
  26.             InputNumbers2(array4Mul);
  27.             Console.WriteLine("The mul in the interval [2,12] is {0}", MulInInterval(array4Mul, 2, 12));
  28.  
  29.             // 3.
  30.             Console.Write("Please enter a = ");
  31.             int a = int.Parse(Console.ReadLine());
  32.  
  33.             Console.Write("Please enter b = ");
  34.             int b = int.Parse(Console.ReadLine());
  35.  
  36.             Console.Write("Please enter c = ");
  37.             int c = int.Parse(Console.ReadLine());
  38.  
  39.             Console.WriteLine(Sum(a * b) + Sum(c));
  40.         }
  41.  
  42.         static int InputNumbers()
  43.         {
  44.             int sum = 0;
  45.             int number = 0;
  46.             do
  47.             {
  48.                 Console.Write("Please, enter the next number (0 for end): ");
  49.                 number = int.Parse(Console.ReadLine());
  50.                 if (number != 0 )
  51.                 {
  52.                     sum += number;
  53.                 }
  54.             } while (number != 0);
  55.             return sum;
  56.         }
  57.  
  58.         static void InputNumbers2(int[] array)
  59.         {
  60.             for (int i = 0; i < array.Length; i++)
  61.             {
  62.                 Console.Write("Please, enter element[{0}] = ", i);
  63.                 array[i] = int.Parse(Console.ReadLine());
  64.             }
  65.         }
  66.  
  67.         static int MulInInterval(int[] array, int min, int max)
  68.         {
  69.             int mul = 1;
  70.             for (int i = 0; i < array.Length; i++)
  71.             {
  72.                 if (array[i] >= min && array[i] <= max)
  73.                 {
  74.                     mul *= array[i];
  75.                 }
  76.             }
  77.             return mul;
  78.         }
  79.  
  80.         static int Sum(int k)
  81.         {
  82.             int sum = 0;
  83.             Random randomGen = new Random();
  84.             int[] array = new int[k];
  85.             for (int i = 0; i < array.Length; i++)
  86.             {
  87.                 array[i] = randomGen.Next();
  88.                 if (array[i] % 2 ==0)
  89.                 {
  90.                     sum += array[i];
  91.                 }
  92.             }
  93.             return sum;
  94.         }
  95.     }
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement