Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace MyExam1
- {
- class Program
- {
- // 2. Make func that multiply arrValues by 2
- static void MultiplyArr(double[] arr, double multiplier)
- {
- for (int i = 0; i < arr.Length; i++)
- arr[i] *= multiplier;
- }
- // 3. make print function using for
- static void PrintArr(double[] arr)
- {
- for (int i = 0; i < arr.Length; i++)
- Console.Write($"{arr[i]}, ");
- }
- // 1. read arr
- private static double[] ReadArray(string input)
- {
- double[] arr = input
- .Split()
- .Select(double.Parse)
- .ToArray();
- if (arr.Length > 10)
- {
- Console.WriteLine("Array is too long, its lenght is: {0}", arr.Length);
- Console.WriteLine("Input corect array");
- input = Console.ReadLine();
- ReadArray(input);
- }
- else
- Console.WriteLine("Aray Lenght is: {0}", arr.Length);
- return arr;
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Input array. If you wanna exit, enter '0'");
- string input = Console.ReadLine();
- while (input != "0")
- {
- double[] arr = ReadArray(input);
- MultiplyArr(arr, 2);
- Console.Write("Aray after multiply: ");
- PrintArr(arr);
- Console.WriteLine();
- Console.WriteLine("Input array. If you wanna exit, enter '0'");
- input = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement