Advertisement
maxlarin2

Rub

Dec 25th, 2013
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. using System;
  2.  
  3. namespace rybezka
  4. {
  5.  
  6. class ArrayPr
  7. {
  8. private double[] array, mass;
  9. public ArrayPr(int size)
  10. {
  11. array = new double[size];
  12. }
  13.  
  14. public int GetAns
  15. {
  16. get
  17. {
  18. return mass.Length;
  19. }
  20.  
  21. }
  22. public ArrayPr(params double[] mas)
  23. {
  24. mass = mas;
  25. }
  26. private double Factorial(double size)
  27. {
  28. double fact = 1;
  29. for (double i = size; i > 0; --i)
  30. {
  31. fact *= i;
  32. }
  33. return fact;
  34. }
  35.  
  36.  
  37. public void SetTaylor(int size, int x)
  38. {
  39. int n;
  40. for (n = 0; n < size; n++)
  41. {
  42. array[n] = (Math.Pow(x, n) / Factorial(n));
  43. }
  44.  
  45. Print(size);
  46. }
  47.  
  48. public void Print(int size)
  49. {
  50. for (int i = 0; i < size; ++i)
  51. Console.Write("{0}; ", Math.Round(array[i], 3));
  52. }
  53.  
  54.  
  55. public double Proizv()
  56. {
  57. int frst = 0, lst = 0;
  58. double ans = 0;
  59. for (int i = 0; i < mass.Length; i++)
  60. {
  61. if (mass[i] == 0)
  62. {
  63. frst = i;
  64. break;
  65. }
  66. }
  67. for (int i = mass.Length - 1; i > 0; i--)
  68. {
  69. if (mass[i] == 0)
  70. {
  71. lst = i;
  72. break;
  73. }
  74. }
  75. for (int i = frst + 1; i <= lst - 1; i++)
  76. ans += mass[i];
  77. return ans;
  78. }
  79. }
  80.  
  81. class MainClass
  82. {
  83. public static void Main(string[] args)
  84. {
  85. int sizeOfArray;
  86. int size;
  87. bool check;
  88.  
  89. Console.Write("Введите размерность массива: ");
  90. check = Int32.TryParse(Console.ReadLine(), out sizeOfArray);
  91. while (check == false)
  92. {
  93.  
  94. Console.Write("Введите размерность массива: ");
  95. check = Int32.TryParse(Console.ReadLine(), out sizeOfArray);
  96. }
  97. ArrayPr input = new ArrayPr(sizeOfArray);
  98. Console.Write("Введите количество элементов для заполнения массива(кол-во элементов должно быть <= размера массива): ");
  99. check = Int32.TryParse(Console.ReadLine(), out size);
  100. while (size > sizeOfArray || check == false)
  101. {
  102. Console.Write("Введите количество элементов для заполнения массива(кол-во элементов должно быть <= размера массива): ");
  103. check = Int32.TryParse(Console.ReadLine(), out size);
  104.  
  105. }
  106. int x = 0;
  107. Console.Write("Введите X: ");
  108. check = Int32.TryParse(Console.ReadLine(), out x);
  109. while (check == false)
  110. {
  111.  
  112. Console.Write("Введите X: ");
  113. check = Int32.TryParse(Console.ReadLine(), out x);
  114. }
  115. input.SetTaylor(size, x);
  116. Console.WriteLine("\n");
  117. int size2 = -1;
  118. Console.Write("Введите размерность массива: ");
  119. check = Int32.TryParse(Console.ReadLine(), out size2);
  120. while (check == false)
  121. {
  122.  
  123. Console.Write("Введите размерность массива: ");
  124. check = Int32.TryParse(Console.ReadLine(), out size2);
  125. }
  126. double[] mas = new double[size2];
  127. for (int i = 0; i < size2; i++)
  128. {
  129. Console.Write("Введите число: ");
  130. check = double.TryParse(Console.ReadLine(), out mas[i]);
  131. while (check == false)
  132. {
  133.  
  134. Console.Write("Введите число: ");
  135. check = double.TryParse(Console.ReadLine(), out mas[i]);
  136. }
  137. }
  138. ArrayPr Ex = new ArrayPr(mas);
  139. Console.WriteLine("Кол-во элементов массива: " + Ex.GetAns);
  140. Console.WriteLine("Сумма между первым и последним нулями : " + Ex.Proizv());
  141. Console.ReadLine();
  142. }
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement