static imagNum product(imagNum n1, imagNum n2) //does math for imaginary num multiplication in ImagProd() { imagNum result; result.real = (n1.real * n2.real) - (n1.imag * n2.imag); result.imag = (n1.real * n2.imag) + (n2.real * n1.imag); return(result); }
public void Show() { Console.WriteLine(@" Измените приводившийся в предыдущей главе пример генератора множества Мандельброта так, чтобы в нем для сложных чисел использовалась следующая структура: struct imagNum { public double real, imag; } "); imagNum coord = new imagNum(); imagNum temp = new imagNum(); double realTemp2, arg; int iterations; for (coord.imag = 1.2; coord.imag >= -1.2; coord.imag -= 0.05) { for (coord.real = -0.6; coord.real <= 1.77; coord.real += 0.03) { iterations = 0; temp.real = coord.real; temp.imag = coord.imag; arg = (coord.real * coord.real) + (coord.imag * coord.imag); while ((arg < 4) && (iterations < 40)) { realTemp2 = (temp.real * temp.real) - (temp.imag * temp.imag) - coord.real; temp.imag = (2 * temp.real * temp.imag) - coord.imag; temp.real = realTemp2; arg = (temp.real * temp.real) + (temp.imag * temp.imag); iterations += 1; } switch (iterations % 4) { case 0: Console.Write("."); break; case 1: Console.Write("o"); break; case 2: Console.Write("O"); break; case 3: Console.Write("@"); break; } } Console.Write("\n"); } Console.ReadKey(); }
static void ImagProd() //option 4 from above { Console.WriteLine("Please enter the real component, then the imaginary (without the i)."); imagNum num1, num2; num1.real = int.Parse(Console.ReadLine()); num1.imag = int.Parse(Console.ReadLine()); Console.WriteLine("Please enter the real component, then the imaginary (without the i)."); num2.real = int.Parse(Console.ReadLine()); num2.imag = int.Parse(Console.ReadLine()); imagNum prod = product(num1, num2); Console.WriteLine("{0} x {1} = {2}", num1.ToString(), num2.ToString(), prod.ToString()); }