Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.61 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 SecondCW
  8. {
  9.   public   class JaggedMatrix
  10.     {
  11.          double[] x;
  12.         double[] arr;
  13.         static Random Rand = new Random();
  14.         public JaggedMatrix(int min, int max, int n)
  15.         {
  16.             arr=new double[n];
  17.             x  =new double[n];
  18.              for(int i =0; i<n; i++)
  19.             {
  20.                 x[i] = Rand.NextDouble() * Rand.Next(min + 1, max);
  21.             }
  22.            
  23.           }      
  24.        
  25.    public  double[]SinArray()
  26.         {
  27.             for(int i=0; i<arr.Length; i++)
  28.             {
  29.                 double temp = 0;
  30.                 do
  31.                 {
  32.                     temp += (Math.Pow(-1, i) / factorial(i)) * Math.Pow(xindex(i), 2 * i + 1);
  33.                 } while (!(i > arr.Length));
  34.                     arr[i]=temp;
  35.             }
  36.             return arr;
  37.         }
  38.         static double factorial(int i)
  39.         {
  40.             if (i == 0) return 0;
  41.             double numb = 2 * i + 1;
  42.             for (int j = 0; j < numb; j++)
  43.             {
  44.                 numb += j;
  45.             }
  46.             return numb;
  47.  
  48.         }
  49.          double xindex(int j )
  50.         {
  51.             double temp = 0;
  52.             for(int i =0; i<arr.Length; i++)
  53.             {
  54.                 if(i==j)
  55.                 {
  56.                     temp = x[i];
  57.                 }
  58.             }
  59.             return temp;
  60.         }
  61.       public  static string[] PrintString(double[]arr)
  62.          {
  63.              string[] StringArr = new string[arr.Length];
  64.             for(int i =0; i<arr.Length; i++)
  65.             {
  66.                 StringArr[i] = string.Format("{0:e:f3}", arr[i]);
  67.             }
  68.             return StringArr;
  69.          }
  70.     }
  71.        
  72.     class Program
  73.     {
  74.        
  75.        
  76.         static void Main(string[] args)
  77.         {
  78.            int min, max, n;
  79.           do Console.WriteLine("Введите Min");
  80.             while (!int.TryParse(Console.ReadLine(), out min));
  81.             do Console.WriteLine("Введите Max");
  82.             while (!int.TryParse(Console.ReadLine(), out max));
  83.             do Console.WriteLine("Введите N");
  84.             while (!int.TryParse(Console.ReadLine(), out n));
  85.             JaggedMatrix obj = new JaggedMatrix(min, max, n);
  86.             double[] Arrik = obj.SinArray();
  87.             string[] StrinArr = JaggedMatrix.PrintString(Arrik);
  88.             for(int i =0; i<StrinArr.Length; i++)
  89.             {
  90.                 Console.WriteLine(StrinArr[i]);
  91.             }
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement