Advertisement
Guest User

перемножение массива

a guest
Jan 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace arrayUmn
  8. {
  9.     class Program
  10.     {
  11.         public static int arraySize()
  12.         {
  13.             int n = 0;
  14.             bool check = false;
  15.             while (!check)
  16.             {
  17.                 try
  18.                 {
  19.                     Console.Write("Введите размер массива:");
  20.                     n = int.Parse(Console.ReadLine());
  21.                     check = true;
  22.                 }
  23.                 catch
  24.                 {
  25.                     Console.WriteLine("Повторите ввод!");
  26.                     check = false;
  27.                 }
  28.             }
  29.             return n;
  30.         }
  31.  
  32.         public static double[] arrayFilling(int n)
  33.         {
  34.             double[] array = new double[n];
  35.             bool check = false;
  36.             for (int i = 0; i < n; i++)
  37.             {
  38.                 while (!check)
  39.                 {
  40.                     try
  41.                     {
  42.                         Console.Write("[" + i + "]" + ":");
  43.                         array[i] = double.Parse(Console.ReadLine());
  44.                         check = true;
  45.                     }
  46.                     catch
  47.                     {
  48.                         Console.WriteLine("Повторите ввод!");
  49.                         check = false;
  50.                     }
  51.                 }
  52.                 check = false;
  53.             }
  54.             return array;
  55.         }
  56.  
  57.         public static double arrayUmn(double[] array, int start, int finish)
  58.         {
  59.             double arrUmn = 1;
  60.             for (int i = start; i < finish; i++)
  61.             {
  62.                 arrUmn *= array[i];
  63.             }
  64.             return arrUmn;
  65.         }
  66.  
  67.         static void Main(string[] args)
  68.         {
  69.             try
  70.             {
  71.                 int n = arraySize();
  72.                 double[] array = arrayFilling(n);
  73.                 Console.WriteLine("Произведение:" + arrayUmn(array, 1, array.Length - 1));
  74.             }
  75.             catch
  76.             {
  77.                 Console.WriteLine("Даже я не знаю что тут могло сломаться:)");
  78.             }
  79.             Console.ReadKey();
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement