Advertisement
Guest User

For Liliya1

a guest
Feb 28th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Введите комплексные числа: ");
  14.             Console.WriteLine("Введите комплексное число 1: ");
  15.             double a1 = Convert.ToDouble(Console.ReadLine());
  16.             double b1 = Convert.ToDouble(Console.ReadLine());
  17.             Console.WriteLine("Введите комплексное число 2: ");
  18.             double a2 = Convert.ToDouble(Console.ReadLine());
  19.             double b2 = Convert.ToDouble(Console.ReadLine());
  20.  
  21.             Console.WriteLine("Выберите действие: ");
  22.  
  23.             int change = Convert.ToInt32(Console.ReadLine());
  24.  
  25.             Console.WriteLine(ComplexNumb(a1, b1, a2, b2, change)[0] + "; " + ComplexNumb(a1, b1, a2, b2, change)[1] + "i");
  26.  
  27.             Console.ReadKey();
  28.         }
  29.  
  30.         public static double[] ComplexNumb(double a1, double b1, double a2, double b2, int vibor)
  31.         {
  32.             double[] temp = new double[2];
  33.             switch (vibor)
  34.             {
  35.                 case 1:
  36.                     temp[0] = a1 + a2;
  37.                     temp[1] = b1 + b2;
  38.                     break;                
  39.                 case 2:
  40.                     temp[0] = a1 - a2;
  41.                     temp[1] = b1 - b2;
  42.                     break;                
  43.                 case 3:
  44.                     temp[0] = a1 * a2 - b1 * b2;
  45.                     temp[1] = a1 * b2 + a2 * b1;
  46.                     break;                
  47.                 case 4:
  48.                     temp[0] = (a1 * a2 + b1 * b2) / (a2 * a2 + b2 * b2);
  49.                     temp[1] = (a2 * b1 - a1* b2) / (a2 * a2 + b2 * b2);
  50.                     break;
  51.             }
  52.             return temp;
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement