Advertisement
Sammers

Untitled

Oct 6th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 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 ConsoleApplication16
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. double tgx = 0;
  14. Console.WriteLine("Введите x");
  15. string str = Console.ReadLine();
  16. int X = int.Parse(str);
  17. if Tg(X,ref double tgx)
  18. Console.WriteLine(tgx);
  19. else Console.WriteLine("ошибка");
  20. }
  21.  
  22. public static double BernulliNumbe(int n)
  23. {
  24. if (n == 0)
  25. return 1;
  26. if (n % 2 == 1)
  27. return 0;
  28. double sum = 0;
  29. for (int k = 1; k < n + 1; k++)
  30. {
  31.  
  32. sum += (Factorial(n + 1) * BernulliNumbe(n - k)) / (Factorial(k + 1) * Factorial(n - k));
  33.  
  34.  
  35. }
  36. return (-1.0 / (n + 1)) * sum;
  37.  
  38.  
  39. }
  40. public static double stepen(double d, int nn)
  41. {
  42. double sum1 = 1.0;
  43. for (int k = 0; k <= nn; k++)
  44. {
  45.  
  46.  
  47. sum1 = sum1 * d;
  48.  
  49.  
  50.  
  51. }
  52. return sum1;
  53. }
  54.  
  55. public static bool Tg(int x, ref double tgx)
  56. {
  57. if (x > (-(Math.PI) / 2) && (x < (Math.PI) / 2))
  58. {
  59. int n =1;
  60.  
  61. double summm=0;
  62. double Psummm=-100;
  63. while (summm - Psummm > 0.01)
  64. {
  65. Psummm=summm;
  66. summm+=( (BernulliNumbe(2*n))*(stepen(-4,n))*(1+stepen(-4,n))/((Factorial(2*n))*(stepen(x,2*n-1))));
  67. n++;
  68. }
  69. tgx=summm;
  70. return true;
  71. }
  72. else
  73. {
  74. tgx = 0;
  75. return false;
  76.  
  77. }
  78. }
  79.  
  80. public static int Factorial(int numb)
  81. {
  82. int res = 1;
  83. for (int i = numb; i > 1; i--)
  84. res *= i;
  85. return res;
  86. }
  87.  
  88.  
  89.  
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement