private void textBox1_TextChanged(object sender, EventArgs e) { label2.Text = "0"; bool ok = int.TryParse(textBox1.Text, out int n); Factorial obj = new Factorial(); if (n > 0 && ok) { label2.Text = Convert.ToString(obj.count(n)); } }
private void button1_Click(object sender, EventArgs e) { if (radioButton1.Checked == true) { Factorial f1 = new Factorial(); f1.Show(); } else if (radioButton2.Checked == true) { Form2 f2 = new Form2(); f2.Show(); } }
private void button1_Click(object sender, EventArgs e) { if (checkedListBox1.CheckedIndices.Count == 0) //check if algorithm is been chosen { MessageBox.Show("Choose algorithm!"); return; } if (textBox1.Text.Length < 1) //check if the represented number string is not empty { MessageBox.Show("Type integer number!"); return; } string checkstring = "0123456789"; try { //Check if the string only consists of the numerals int SymbolsCount = 0; foreach (char c in checkstring) { for (int i = 0; i < textBox1.Text.Length; i++) { if (textBox1.Text[i] == c) { SymbolsCount++; } } } if (SymbolsCount == textBox1.Text.Length) { AccurateFactorial n = new AccurateFactorial(textBox1.Text); n = n.DisposeZero(n); //Dispose of extra zeros in the beginning textBox1.Text = n.ToString(); //Choosing different methods depending on the selected algorithm if (checkedListBox1.CheckedIndices[0] != 5) { if (long.TryParse(textBox1.Text, out long m)) { switch (checkedListBox1.CheckedIndices[0]) { case 0: textBox2.Text = Factorial.GetFactorialWithCycles(m).ToString(); break; case 1: textBox2.Text = Factorial.GetFactorial(m).ToString(); break; case 2: textBox2.Text = Factorial.Approximation(m, "Ramanujan").ToString(); break; case 3: textBox2.Text = Factorial.Approximation(m, "Stirling").ToString(); break; case 4: textBox2.Text = Factorial.Approximation(m, "").ToString(); break; } if (long.TryParse(textBox2.Text, out long k)) { if (k < 1 || m > 20) {//Coud not calculate the factorial textBox2.Text = "Error"; MessageBox.Show("The number is too big for the current method"); return; } } } return; } //check if the number is small enough if (n.value.Length > 4 || (n.value.Length > 3 && n.value[0] > 6 && n.value[1] > 7)) { textBox2.Text = $"The number {n.ToString()} is too big integer number (>=7500)"; return; } Factorial f = new Factorial(); //I made all methods to be used in the Factorial class n = new AccurateFactorial(f.Accurate(n).value); //calculate using the best method textBox2.Text = n.ToString(); //write result } else { textBox2.Text = "Error: the string must contain only numerals"; } } catch (Exception) { MessageBox.Show("Unkown Error"); } }