fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner in = new Scanner(System.in);
  10. double mu=0;
  11. int n=in.nextInt();
  12. double[][] x = new double[n][n];
  13. double[][] y = new double[n][n];
  14. double[][] z = new double[n][n];
  15. for (int i = 0; i < n; i++){
  16. for (int j = 0; j < n; j++){
  17. x[i][j]=in.nextDouble();;
  18. y[j][i]=x[i][j];
  19. }
  20. }
  21. for (int i = 0; i < n; i++){
  22. for (int j = 0; j < n; j++){
  23. for (int p = 0; p < n; p++){
  24. mu += x[i][p]*y[p][j];
  25. }
  26. z[i][j] = mu;
  27. mu = 0;
  28. }
  29. }
  30. for (int i = 0; i < n; i++){
  31. for (int j = 0; j < n; j++){
  32. System.out.printf("%.1f ",z[i][j]);
  33. }
  34. System.out.println();
  35. }
  36. }
  37. }
Success #stdin #stdout 0.16s 321344KB
stdin
4
1.2 2 3 4
5 6 7 8
9 0 1 2
3 4 5 6
stdout
30.4 71.0 21.8 50.6 
71.0 174.0 68.0 122.0 
21.8 68.0 86.0 44.0 
50.6 122.0 44.0 86.0