Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Лаба2задание3
- {
- class Program
- {
- private static void Main(string[] args)
- {
- bool ok = false;
- while (!ok)
- {
- Console.WriteLine("Введите число элементов:");
- if (Int32.TryParse(Console.ReadLine(), out int n) && n > 0)
- {
- Console.WriteLine("Введите x:");
- if (Int32.TryParse(Console.ReadLine(), out int x))
- {
- double r = 0;
- if (n % 2 == 0) // n - четное число
- {
- r = Math.Cos(x * n);
- }
- else // n-нечетное число
- {
- r = Math.Sin(x * n);
- }
- for (int i = n - 1; i > 0; i--)
- {
- double z = ((i % 4) - 2 == 0) ? -1 : 1;// z определяет, будет перед функцией минус или плюс
- if (i % 2 == 0)
- r = z * Math.Cos(i * x + r);
- if (i % 2 == 1)
- r = z * Math.Sin(i * x + r);
- }
- Console.WriteLine("Ответ: {0}", r);
- Console.ReadLine();
- ok = true;
- }
- else
- {
- Console.WriteLine("Ошибка ввода x!");
- }
- }
- else
- {
- Console.WriteLine("Ошибка ввода n!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement