Advertisement
YORDAN2347

11a, exc 1

Jan 19th, 2021
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace MyExam1
  5. {
  6.     class Program
  7.     {
  8.         // 2. Make func that multiply arrValues by 2
  9.         static void MultiplyArr(double[] arr, double multiplier)
  10.         {
  11.             for (int i = 0; i < arr.Length; i++)
  12.                 arr[i] *= multiplier;
  13.         }
  14.  
  15.         // 3. make print function using for
  16.         static void PrintArr(double[] arr)
  17.         {
  18.             for (int i = 0; i < arr.Length; i++)
  19.                 Console.Write($"{arr[i]}, ");
  20.         }
  21.  
  22.         // 1. read arr
  23.         private static double[] ReadArray(string input)
  24.         {
  25.             double[] arr = input
  26.                     .Split()
  27.                     .Select(double.Parse)
  28.                     .ToArray();
  29.             if (arr.Length > 10)
  30.             {
  31.                 Console.WriteLine("Array is too long, its lenght is: {0}", arr.Length);
  32.                 Console.WriteLine("Input corect array");
  33.                 input = Console.ReadLine();
  34.                 ReadArray(input);
  35.             }
  36.             else
  37.                 Console.WriteLine("Aray Lenght is: {0}", arr.Length);
  38.             return arr;
  39.         }
  40.  
  41.         static void Main(string[] args)
  42.         {
  43.            
  44.             Console.WriteLine("Input array. If you wanna exit, enter '0'");
  45.             string input = Console.ReadLine();
  46.             while (input != "0")
  47.             {
  48.                 double[] arr = ReadArray(input);
  49.  
  50.  
  51.                 MultiplyArr(arr, 2);
  52.  
  53.                 Console.Write("Aray after multiply: ");
  54.                 PrintArr(arr);
  55.                 Console.WriteLine();
  56.  
  57.                 Console.WriteLine("Input array. If you wanna exit, enter '0'");
  58.                 input = Console.ReadLine();
  59.             }
  60.         }
  61.     }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement