fork download
  1. //ю4.9
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class FifthLab
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. Scanner input = new Scanner(System.in);
  12. int n, m;
  13.  
  14. n = input.nextInt();
  15. m = input.nextInt();
  16.  
  17. double[][] A = new double[n][m];
  18.  
  19. for(int i = 0; i < n; i++)
  20. {
  21. for(int j = 0; j < m; j++)
  22. {
  23. A[i][j] = input.nextDouble();
  24. }
  25. }
  26.  
  27. for(int i = 0; i < n; i++)
  28. {
  29. for(int j = 0; j < m; j++)
  30. {
  31. if(A[i][j] != 0)
  32. {
  33. A[i][j] = -(1/A[i][j]);
  34. }
  35. }
  36. }
  37.  
  38. for(int i = 0; i < n; i++)
  39. {
  40. for(int j = 0; j < m; j++)
  41. {
  42. System.out.printf("%.3f ",A[i][j]);
  43. }
  44. System.out.println();
  45. }
  46. }
  47. }
Success #stdin #stdout 0.08s 4386816KB
stdin
3
4
-3
-9
15
12
-31
-8
2
8
 -1
2
-6
-8
stdout
0.333 0.111 -0.067 -0.083 
0.032 0.125 -0.500 -0.125 
1.000 -0.500 0.167 0.125