summaryrefslogtreecommitdiff
path: root/sem_2/HLIN202/TP/TP9-10/exopart2.cpp
blob: cec072504f42ebd16dbff87ec9b3885d826a98d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>

float** MatMul ( float ** m1, float ** m2, int m, int n, int p) {
  float ** ret= new float*[n];
  for ( int i = 0; i<n;i++){
    ret[i]=new float[n];
  }
  for (int i = 0; i<n;i++){
    for ( int j=0; j < n; j ++){
      for ( int k=0; k<m; k ++) {
        for ( int l=0; l<n;l++){
          ret[i][j]+= m1[k][l]*m2[l][k];
        }
      }
    }
  }
  return ret;
}

float ** CreerMat ( int m, int n){
  float **T= new float*[m];
  for (int i = 0; i < m; i ++) {
    T[i]= new float[n];
  }
  for (int i = 0; i < m; i ++) {
    for (int j= 0; j <n; j ++) {
      T[i][j] = 1/(float)(i+j+1);
    }
  }
  return T;
}
void afficheMat ( float **Mat, int lignes, int colonnes){
  for ( int i = 0; i<lignes; i ++) {
    for (int j = 0; j < colonnes;j++){
      std::cout<<Mat[i][j]<<" ";
    }
    std::cout<<std::endl;
  }
  std::cout<<std::endl;
}

int main () {
  int m,n;
  std::cin>>m>>n;

  float **T;

  T=MatMul(CreerMat(m,n),CreerMat(m,n), m,n,n);
  afficheMat(T, m,n);
  return 0;
}