fork download
  1. using System;
  2.  
  3. public class RootOfSquareMatrix
  4. {
  5. public static void Main()
  6. {
  7. double[,] A = new double[2,2];
  8. double[,] B = new double[2,2];
  9. int[,] I = {{1, 0}, {0, 1}};
  10. for (int i=0; i<2; i++)
  11. {
  12. for (int j=0; j<2; j++)
  13. {
  14. A[i,j] = Convert.ToDouble(Console.ReadLine());
  15. }
  16. }
  17. double tr_A = A[0,0]+ A[1,1];
  18. double sqrt_det_A = Math.Sqrt(A[0,0]*A[1,1] - A[0,1]*A[1,0]);
  19. double divisor = Math.Sqrt(tr_A + 2*sqrt_det_A);
  20. for (int i=0; i<2; i++)
  21. {
  22. for (int j=0; j<2; j++)
  23. {
  24. B[i,j] = (A[i,j] + sqrt_det_A*I[i,j]) / divisor;
  25. }
  26. }
  27. Console.WriteLine("Matrix A:\n{0} {1}\n{2} {3}", A[0,0], A[0,1], A[1,0], A[1,1]);
  28. Console.WriteLine("Square root of matrix A:\n{0} {1}\n{2} {3}", B[0,0], B[0,1], B[1,0], B[1,1]);
  29. }
  30. }
  31.  
Success #stdin #stdout 0.05s 28300KB
stdin
5
8
13
21
stdout
Matrix A:
5 8
13 21
Square root of matrix A:
1.1338934190276817 1.5118578920369088
2.456769074559977 4.157609203101499