fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n;
  7. cin >> n;
  8. double a[n][n], aa[n][n], result1[n][n], result2[n][n];
  9. for (int i = 0; i < n; i++)
  10. {
  11. for (int j = 0; j < n; j++)
  12. {
  13. cin >> a[i][j];
  14. aa[j][i] = a[i][j];
  15. }
  16. }
  17. for (int i = 0; i < n; i ++)
  18. {
  19. for (int j = 0; j < n; j ++)
  20. {
  21. result1[i][j] = 0.5 * ( a[i][j] + aa[i][j] );
  22. result2[i][j] = 0.5 * ( a[i][j] - aa[i][j] );
  23. }
  24. }
  25. for (int i = 0; i < n; i++)
  26. {
  27. for (int j = 0; j < n; j++)
  28. {
  29. cout << result1[i][j] << ' ';
  30. }
  31. cout << endl;
  32. }
  33. cout << endl;
  34. for (int i = 0; i < n; i ++)
  35. {
  36. for (int j = 0; j < n; j ++)
  37. {
  38. cout << result2[i][j] << ' ';
  39. }
  40. cout << endl;
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0s 3276KB
stdin
3
1 2 3
2 4 6
1 4 8
stdout
1 2 2 
2 4 5 
2 5 8 

0 0 1 
0 0 1 
-1 -1 0