Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace rybezka
- {
- class ArrayPr
- {
- private double[] array, mass;
- public ArrayPr(int size)
- {
- array = new double[size];
- }
- public int GetAns
- {
- get
- {
- return mass.Length;
- }
- }
- public ArrayPr(params double[] mas)
- {
- mass = mas;
- }
- private double Factorial(double size)
- {
- double fact = 1;
- for (double i = size; i > 0; --i)
- {
- fact *= i;
- }
- return fact;
- }
- public void SetTaylor(int size, int x)
- {
- int n;
- for (n = 0; n < size; n++)
- {
- array[n] = (Math.Pow(x, n) / Factorial(n));
- }
- Print(size);
- }
- public void Print(int size)
- {
- for (int i = 0; i < size; ++i)
- Console.Write("{0}; ", Math.Round(array[i], 3));
- }
- public double Proizv()
- {
- int frst = 0, lst = 0;
- double ans = 0;
- for (int i = 0; i < mass.Length; i++)
- {
- if (mass[i] == 0)
- {
- frst = i;
- break;
- }
- }
- for (int i = mass.Length - 1; i > 0; i--)
- {
- if (mass[i] == 0)
- {
- lst = i;
- break;
- }
- }
- for (int i = frst + 1; i <= lst - 1; i++)
- ans += mass[i];
- return ans;
- }
- }
- class MainClass
- {
- public static void Main(string[] args)
- {
- int sizeOfArray;
- int size;
- bool check;
- Console.Write("Введите размерность массива: ");
- check = Int32.TryParse(Console.ReadLine(), out sizeOfArray);
- while (check == false)
- {
- Console.Write("Введите размерность массива: ");
- check = Int32.TryParse(Console.ReadLine(), out sizeOfArray);
- }
- ArrayPr input = new ArrayPr(sizeOfArray);
- Console.Write("Введите количество элементов для заполнения массива(кол-во элементов должно быть <= размера массива): ");
- check = Int32.TryParse(Console.ReadLine(), out size);
- while (size > sizeOfArray || check == false)
- {
- Console.Write("Введите количество элементов для заполнения массива(кол-во элементов должно быть <= размера массива): ");
- check = Int32.TryParse(Console.ReadLine(), out size);
- }
- int x = 0;
- Console.Write("Введите X: ");
- check = Int32.TryParse(Console.ReadLine(), out x);
- while (check == false)
- {
- Console.Write("Введите X: ");
- check = Int32.TryParse(Console.ReadLine(), out x);
- }
- input.SetTaylor(size, x);
- Console.WriteLine("\n");
- int size2 = -1;
- Console.Write("Введите размерность массива: ");
- check = Int32.TryParse(Console.ReadLine(), out size2);
- while (check == false)
- {
- Console.Write("Введите размерность массива: ");
- check = Int32.TryParse(Console.ReadLine(), out size2);
- }
- double[] mas = new double[size2];
- for (int i = 0; i < size2; i++)
- {
- Console.Write("Введите число: ");
- check = double.TryParse(Console.ReadLine(), out mas[i]);
- while (check == false)
- {
- Console.Write("Введите число: ");
- check = double.TryParse(Console.ReadLine(), out mas[i]);
- }
- }
- ArrayPr Ex = new ArrayPr(mas);
- Console.WriteLine("Кол-во элементов массива: " + Ex.GetAns);
- Console.WriteLine("Сумма между первым и последним нулями : " + Ex.Proizv());
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement