Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class Matrix{
  5. public:
  6. Matrix(int n){
  7. this->n=n;
  8. int i,j;
  9. cout<<"Introduce matricea:";
  10.  
  11. for(i=0;i<n;i++)
  12. for(j=0;j<n;j++)
  13. cin>>a[i][j];
  14. }
  15. void toString(){
  16. for(int i=0;i<n;i++){
  17. cout<<endl;
  18. for(int j=0;j<n;j++)
  19. cout<<this->a[i][j]<<" ";
  20. }
  21. }
  22. Matrix adunare(Matrix b){
  23. if(b.n == this->n){
  24. int i,j;
  25.  
  26.  
  27. for(i=0;i<n;i++)
  28. for(j=0;j<n;j++)
  29. b.a[i][j]=this->a[i][j]+b.a[i][j];
  30.  
  31. }
  32. return b;
  33. }
  34. Matrix inmultire(Matrix b){
  35. if(b.n == this->n){
  36. int i,j,l;
  37.  
  38. int c[100][100];
  39. for(i=0;i<n;i++)
  40. for(j=0;j<n;j++)c[i][j]=0;
  41.  
  42. for(i=0;i<n;i++)
  43. for(j=0;j<n;j++)
  44. for(l=j;l<=n;l++){
  45. c[i][j]=this->a[i][l]+b.a[l][j];
  46.  
  47. }
  48. for(i=0;i<n;i++){
  49.  
  50. for(j=0;j<n;j++){
  51. b.a[i][j]=c[i][j];
  52.  
  53. }
  54. }
  55. }
  56. return b;
  57. }
  58.  
  59. private:
  60. int a[100][100],n;
  61.  
  62. };
  63. int main()
  64. {
  65.  
  66. Matrix a = Matrix(2);
  67. Matrix b = Matrix(2);
  68. a.toString();
  69. b=a.inmultire(b);
  70. b.toString();
  71.  
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement