fork(1) download
  1. //(c)Terminator
  2. #include <iostream>
  3. #include <iterator>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main(void){
  9. const int N = 3;
  10.  
  11. int ma[N][N] = {
  12. { 1, 2, 3 },
  13. { 4, 3, 1 },
  14. { 0, 1, 2 }
  15. };
  16.  
  17. int mb[N][N] = {
  18. { 2, 1, 8 },
  19. { 3, 4, 1 },
  20. { 9, 4, 2 }
  21. };
  22.  
  23. int mc[N][N];
  24. int i;
  25.  
  26.  
  27. //перемножение
  28. for(int ir = 0; ir < N; ++ir) {
  29. for(int c = 0; c < N; ++c) {
  30. mc[ir][c] = 0;
  31. for(int r = 0; r < N; ++r)
  32. mc[ir][c] += ma[ir][r] * mb[r][c];
  33. }
  34. }
  35.  
  36. //вывести результирующею матрицу
  37. ostream_iterator<int> _op(cout, "\t");
  38. for(i = 0; i < N; ++i){
  39. copy(mc[i], mc[i] + N, _op);
  40. cout << endl;
  41. }
  42.  
  43. //...
  44.  
  45. //транспонирование
  46. for(i = 0; i < N; ++i) {
  47. for(int j = i; j < N; ++j)
  48. swap(mc[i][j], mc[j][i]);
  49. }
  50.  
  51. cout << endl;
  52. for(i = 0; i < N; ++i){
  53. copy(mc[i], mc[i] + N, _op);
  54. cout << endl;
  55. }
  56. return 0;
  57. }
  58.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
35	21	16	
26	20	37	
21	12	5	

35	26	21	
21	20	12	
16	37	5