Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 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 ConsoleApplication2
  8. {
  9.     class Program
  10.     {
  11.         public static String solveMatrix(double A1, double B1, double A2, double B2, double C, double D)
  12.         {
  13.             // A1,2 - коэф. при 1й неизв.перем. в 1м и 2м уравн.
  14.             // B1,2 - коэф. при 2й неизв.перем. в 1м и 2м уравн.
  15.             // C - коэф. правой части 1го уравн.
  16.             // D - коэф. правой части 2го уравн.
  17.  
  18.             double determinant = A1 * B2 - B1 * A2;
  19.  
  20.             if (determinant == 0.0) // если определитель меньше 0, то корней нет
  21.                 return "No roots";
  22.  
  23.             // Решим по методу Крамера
  24.             double x = (C * B2 - B1 * D) / determinant;
  25.             double y = (A1 * D - C * A2) / determinant;
  26.  
  27.             return String.Format("x: {0} y: {1}", x, y);
  28.         }
  29.  
  30.         static void Main(string[] args)
  31.         {
  32.             double A1, B1, A2, B2, C, D;
  33.  
  34.             A1 = double.Parse(Console.ReadLine());
  35.             B1 = double.Parse(Console.ReadLine());
  36.             A2 = double.Parse(Console.ReadLine());
  37.             B2 = double.Parse(Console.ReadLine());
  38.             C = double.Parse(Console.ReadLine());
  39.             D = double.Parse(Console.ReadLine());
  40.  
  41.             Console.WriteLine(solveMatrix(A1, B1, A2, B2, C, D));
  42.             Console.ReadLine();
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement