Advertisement
nedoproger

лаба2з3

Nov 19th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Лаба2задание3
  4. {
  5. class Program
  6. {
  7. private static void Main(string[] args)
  8. {
  9.  
  10. bool ok = false;
  11. while (!ok)
  12. {
  13. Console.WriteLine("Введите число элементов:");
  14. if (Int32.TryParse(Console.ReadLine(), out int n) && n > 0)
  15. {
  16. Console.WriteLine("Введите x:");
  17. if (Int32.TryParse(Console.ReadLine(), out int x))
  18. {
  19. double r = 0;
  20. if (n % 2 == 0) // n - четное число
  21. {
  22. r = Math.Cos(x * n);
  23. }
  24. else // n-нечетное число
  25. {
  26. r = Math.Sin(x * n);
  27. }
  28. for (int i = n - 1; i > 0; i--)
  29. {
  30.  
  31. double z = ((i % 4) - 2 == 0) ? -1 : 1;// z определяет, будет перед функцией минус или плюс
  32.  
  33. if (i % 2 == 0)
  34. r = z * Math.Cos(i * x + r);
  35. if (i % 2 == 1)
  36. r = z * Math.Sin(i * x + r);
  37. }
  38. Console.WriteLine("Ответ: {0}", r);
  39. Console.ReadLine();
  40. ok = true;
  41. }
  42. else
  43. {
  44. Console.WriteLine("Ошибка ввода x!");
  45. }
  46. }
  47. else
  48. {
  49. Console.WriteLine("Ошибка ввода n!");
  50. }
  51. }
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement