Tag: 乘法

如何将数组中的所有值相乘?

我有一个任务,我需要找到数组中所有数字的乘积,我不知道如何做到这一点。 int[] numbers = new int[SIZE]; Console.WriteLine(“Type in 10 numbers”); Console.WriteLine(“To stop, type in 0”); for (int input = 0; input < SIZE; input++) { userInput = Console.ReadLine(); numberInputed = int.Parse(userInput); if (numberInputed == ZERO) { numberInputed = ONE; break; } else { numbers[input] = numberInputed; } } 这是我试图找到数组中所有数字的乘积的地方。 foreach (int value in numbers) { […]

双变量保持错误的值

与Math.Atan2类似的问题或C#中的类实例问题并添加两个给出错误结果的双重问题 这是简单的线条: public static String DegreeToRadianStr(Double degree) { Double piBy180 = (Math.PI / 180); Double Val = (piBy180 * degree); // Here it is giving wrong value } piBy180 *度= -3.1415926535897931但是Val = -3.1415927410125732 替代文字http://www.imagechicken.com/uploads/1262936639009840000.jpg我真的不知道该怎么做..请问一些有关这方面的问题,以便我可以指出哪里出错了。 令人惊讶的是,piBy180保持了正确的价值。 同样的事情也发生在其他function上,但有些我操纵如何获得正确的值。 我正在使用MS Visual Studio的C#.net SP1。

C#,运算符’*’不能应用于’double’和’decimal’类型的操作数

这个错误应该是一个简单的错误,但我似乎无法使它工作。 问题在于,这个相同的代码在程序的早期工作。 我没有看到任何理由在这个实例上发送错误而不是之前的四个错误。 参考下面的代码,随意提供任何批评,因为它应该让我更好。 如果重要,我正在使用Sharp Develop 2.2。 以下是有效代码示例: void calc2Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(tb2_fla.Text) & String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_fla.Text) & String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_e.Text)) { MessageBox.Show(“Enter either kVA and Voltage or FLA and Voltage”, “Invalid Data Entry”, MessageBoxButtons.OK); } if (!String.IsNullOrEmpty(tb2_kva.Text) & !String.IsNullOrEmpty(tb2_e.Text)) { decimal x, y, z; x = decimal.Parse(tb2_kva.Text); y = decimal.Parse(tb2_e.Text); z […]

如何在C#中乘以矩阵?

我不能让这种方法起作用。 它打算将矩阵乘以给定的矩阵。 有人可以帮我纠正吗? class Matriz { public double[,] structure; //Other class methods public void multiplyBy(Matrix m) { if (this.structure.GetLength(1) == m.structure.GetLength(0)) { Matriz resultant = new Matriz(this.structure.GetLength(0), m.structure.GetLength(1)); for (int i = 0; i < this.structure.GetLength(0) – 1; i++) { for (int j = 0; j < m.structure.GetLength(1) – 1; j++) { resultant.structure[i, j] = […]