Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SecondCW
- {
- public class JaggedMatrix
- {
- double[] x;
- double[] arr;
- static Random Rand = new Random();
- public JaggedMatrix(int min, int max, int n)
- {
- arr=new double[n];
- x =new double[n];
- for(int i =0; i<n; i++)
- {
- x[i] = Rand.NextDouble() * Rand.Next(min + 1, max);
- }
- }
- public double[]SinArray()
- {
- for(int i=0; i<arr.Length; i++)
- {
- double temp = 0;
- do
- {
- temp += (Math.Pow(-1, i) / factorial(i)) * Math.Pow(xindex(i), 2 * i + 1);
- } while (!(i > arr.Length));
- arr[i]=temp;
- }
- return arr;
- }
- static double factorial(int i)
- {
- if (i == 0) return 0;
- double numb = 2 * i + 1;
- for (int j = 0; j < numb; j++)
- {
- numb += j;
- }
- return numb;
- }
- double xindex(int j )
- {
- double temp = 0;
- for(int i =0; i<arr.Length; i++)
- {
- if(i==j)
- {
- temp = x[i];
- }
- }
- return temp;
- }
- public static string[] PrintString(double[]arr)
- {
- string[] StringArr = new string[arr.Length];
- for(int i =0; i<arr.Length; i++)
- {
- StringArr[i] = string.Format("{0:e:f3}", arr[i]);
- }
- return StringArr;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int min, max, n;
- do Console.WriteLine("Введите Min");
- while (!int.TryParse(Console.ReadLine(), out min));
- do Console.WriteLine("Введите Max");
- while (!int.TryParse(Console.ReadLine(), out max));
- do Console.WriteLine("Введите N");
- while (!int.TryParse(Console.ReadLine(), out n));
- JaggedMatrix obj = new JaggedMatrix(min, max, n);
- double[] Arrik = obj.SinArray();
- string[] StrinArr = JaggedMatrix.PrintString(Arrik);
- for(int i =0; i<StrinArr.Length; i++)
- {
- Console.WriteLine(StrinArr[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement