Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2. #include <iostream>
  3. #include <stdio>
  4. #include <stdlib>
  5. #include <conio.h>
  6. #include <vcl.h>
  7. #include <math.h>
  8. #pragma hdrstop
  9. #define MAX 3
  10.  
  11. //---------------------------------------------------------------------------
  12.  
  13. #pragma argsused
  14. void wczytaj(int a[MAX][MAX])
  15. {
  16. for(int x=0;x<MAX;x++)
  17. {
  18. for(int z=0;z<MAX;z++)
  19. {
  20. printf("Podaj kolejna wartosc macierzy \n");
  21. scanf("%d",&a[x][z]);
  22. }
  23. }
  24. }
  25. void wypisz(int a[MAX][MAX])
  26. {
  27. for(int x=0;x<MAX;x++)
  28. {
  29. for(int z=0;z<MAX;z++)
  30. {
  31. printf("%d ",a[x][z]);
  32. }
  33.  
  34. printf("\n");
  35. }
  36. }
  37. void dodaj(int a[MAX][MAX],int b[MAX][MAX],int c[MAX][MAX])
  38. {
  39. for(int x=0;x<MAX;x++)
  40. {
  41. for(int z=0;z<MAX;z++)
  42. {
  43. c[x][z]=a[x][z]+b[x][z];
  44.  
  45. }
  46. }
  47. }
  48. void odejmij(int a[MAX][MAX],int b[MAX][MAX],int c[MAX][MAX])
  49. {
  50. for(int x=0;x<MAX;x++)
  51. {
  52. for(int z=0;z<MAX;z++)
  53. {
  54. c[x][z]=a[x][z]-b[x][z];
  55.  
  56. }
  57. }
  58. }
  59. void transponuj(int a[MAX][MAX],int b[MAX][MAX])
  60. {
  61. for(int x=0;x<MAX;x++)
  62. {
  63. for(int z=0;z<MAX;z++)
  64. {
  65. b[x][z]=a[z][x];
  66.  
  67.  
  68. }
  69. }
  70. }
  71. void mnozenie(int a[MAX][MAX],int b[MAX][MAX],int c[MAX][MAX])
  72. {
  73. for(int x=0;x<MAX;x++)
  74. {
  75. for(int z=0;z<MAX;z++)
  76. {
  77. int suma;
  78. suma=0;
  79. for( int l=0;l<MAX;l++)
  80. {
  81. suma=suma+a[x][z]*b[x][z];
  82. }
  83. c[x][z]=suma;
  84.  
  85. }
  86. }
  87. }
  88. int main(int argc, char* argv[])
  89. {
  90. int a[MAX][MAX];
  91. int b[MAX][MAX];
  92. int c[MAX][MAX];
  93. wczytaj(a);
  94. wczytaj(b);
  95. wypisz(a);
  96. dodaj(a,b,c);
  97. printf("wynik dodawania to: \n");
  98. wypisz(c);
  99. odejmij(a,b,c);
  100. printf("wynik odejmowania to: \n");
  101. wypisz(c);
  102. transponuj(a,b);
  103. printf("Macierz po transpozycji \n");
  104. wypisz(b);
  105. mnozenie(a,b,c);
  106. printf("Macierz po mnozeniu \n");
  107. wypisz(c);
  108. getch();
  109. return 0;
  110. }
  111.  
  112.  
  113. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement