Как связать функцию с NumericUpDown? - C#
Формулировка задачи:
Пытаюсь написать программу, точнее написать формулу
Помогите, пожалуйста, как то связать эту функцию с NumericUpDown(в коде nud1) и с текст боксом(в коде tb1).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Numerics;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static BigInteger Fact(int n)
{
BigInteger Pn = 1;
BigInteger f = 1;
BigInteger ff = 1;
if (n % 2 == 0)
{
for (int i = 2; i < n; i += 2)
{
ff *= 2 * i - 5;
}
}
else
{
for (int i = 1; i < n; i += 2)
{
ff *= 2 * i - 5;
}
}
for (int i = 1; i < n - 1; i++)
{
f *= i - 1;
}
Math.Pow(2, n - 2);
return Pn;
}
private void btn1_Click(object sender, EventArgs e)
{
}
private void btn2_Click(object sender, EventArgs e)
{
tb1.Clear();
nud1.Value = 3;
}
}
}Решение задачи: «Как связать функцию с NumericUpDown?»
textual
Листинг программы
using System;
using System.Numerics;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(F(10));
}
public static BigInteger F(int n)
{
if (n < 2)
throw new ArithmeticException("Function is not defined for N < 2");
var x = FacFac(2 * n - 5);
var y = Fac(n - 1);
var z = BigInteger.Pow(2, n - 2);
return x * z / y;
}
public static BigInteger Fac(int n)
{
if (n < 0)
throw new ArithmeticException("Factorial for negative is not defined");
BigInteger result = BigInteger.One;
for (int i = 2; i <= n; i++)
{
result *= i;
}
return result;
}
public static BigInteger FacFac(int n)
{
if (n < 0)
throw new ArithmeticException("Double factorial for negative is not defined");
BigInteger result = BigInteger.One;
for (int i = 2 - n % 2; i <= n; i += 2)
{
result *= i;
}
return result;
}
}