private void BotonOA_Click(object sender, EventArgs e) { try { var num1 = NumeroComplejo.Parse(textBoxOA1.Text); var num2 = int.Parse(textBoxOA2.Text); if (num2 <= 0) { throw new Exception("Debe ingresar un numero natural."); } Raiz[] res; switch ((OperacionesAvanzadas)comboBoxOA.SelectedItem) { case OperacionesAvanzadas.Potenciacion: res = new Raiz[1]; res[0] = new Raiz { NumeroComplejo = num1.Pow(num2) }; break; case OperacionesAvanzadas.Radicacion: res = num1.Root(num2); break; default: throw new Exception("Seleccione una operacion"); } listBoxOA.DataSource = res; labelResulOA.Visible = listBoxOA.Visible = true; } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
public Raiz[] Root(int n) { var vec = new Raiz[n]; for (int k = 0; k < n; k++) { vec[k] = new Raiz(); vec[k].NumeroComplejo = new FormaPolar(Math.Pow(Modulo, 1.0 / n), (Argumento + 2 * k * Math.PI) / n); vec[k].EsPrimitiva = Helper.MCD(n, k) == 1; } return(vec); }