Как связать функцию с NumericUpDown? - C#

Узнай цену своей работы

Формулировка задачи:

Пытаюсь написать программу, точнее написать формулу Помогите, пожалуйста, как то связать эту функцию с NumericUpDown(в коде nud1) и с текст боксом(в коде tb1).
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Numerics;
  11. namespace WindowsFormsApplication2
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. static BigInteger Fact(int n)
  20. {
  21. BigInteger Pn = 1;
  22. BigInteger f = 1;
  23. BigInteger ff = 1;
  24. if (n % 2 == 0)
  25. {
  26. for (int i = 2; i < n; i += 2)
  27. {
  28. ff *= 2 * i - 5;
  29. }
  30. }
  31. else
  32. {
  33. for (int i = 1; i < n; i += 2)
  34. {
  35. ff *= 2 * i - 5;
  36. }
  37. }
  38. for (int i = 1; i < n - 1; i++)
  39. {
  40. f *= i - 1;
  41. }
  42. Math.Pow(2, n - 2);
  43. return Pn;
  44. }
  45.  
  46. private void btn1_Click(object sender, EventArgs e)
  47. {
  48. }
  49. private void btn2_Click(object sender, EventArgs e)
  50. {
  51. tb1.Clear();
  52. nud1.Value = 3;
  53. }
  54. }
  55. }

Решение задачи: «Как связать функцию с NumericUpDown?»

textual
Листинг программы
  1. using System;
  2. using System.Numerics;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         Console.WriteLine(F(10));
  9.     }
  10.  
  11.     public static BigInteger F(int n)
  12.     {
  13.         if (n < 2)
  14.             throw new ArithmeticException("Function is not defined for N < 2");
  15.         var x = FacFac(2 * n - 5);
  16.         var y = Fac(n - 1);
  17.         var z = BigInteger.Pow(2, n - 2);
  18.         return x * z / y;
  19.     }
  20.  
  21.     public static BigInteger Fac(int n)
  22.     {
  23.         if (n < 0)
  24.             throw new ArithmeticException("Factorial for negative is not defined");
  25.         BigInteger result = BigInteger.One;
  26.         for (int i = 2; i <= n; i++)
  27.         {
  28.             result *= i;
  29.         }
  30.         return result;
  31.     }
  32.  
  33.     public static BigInteger FacFac(int n)
  34.     {
  35.         if (n < 0)
  36.             throw new ArithmeticException("Double factorial for negative is not defined");
  37.         BigInteger result = BigInteger.One;
  38.         for (int i = 2 - n % 2; i <= n; i += 2)
  39.         {
  40.             result *= i;
  41.         }
  42.         return result;
  43.     }
  44. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

12   голосов , оценка 3.75 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы