Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int **tworz_tab(int n){
  9. int **TAB;
  10. TAB=new int *[n];
  11. for(int i=0; i<n ; i++){
  12. TAB[i]=new int [n];
  13.  
  14. }
  15. return TAB;
  16. }
  17.  
  18.  
  19. void wypelnij(int **TAB,int n, int a, int b){
  20. for (int i=0; i<n ; i++){
  21. for (int j=0; j<n ; j++){
  22. TAB[i][j]=a+rand()%(b+1-a);
  23. }
  24. }
  25. }
  26.  
  27. void drukuj (int **TAB, int n){
  28. for (int i=0; i<n ; i++){
  29. for (int j=0; j<n ; j++){
  30. cout<<TAB[i][j]<<"__";
  31. }
  32. cout<<endl;
  33. }
  34. }
  35.  
  36.  
  37. void *srednia_wek(int **TAB,int n,double *WEK){
  38.  
  39. for (int i=0; i<n ; i++){
  40. double suma=0;
  41. double srednia=0;
  42. for (int j=0; j<n ; j++){
  43. suma+=TAB[j][i];
  44. }
  45. srednia = (double) (suma/n);
  46. WEK[i]=srednia;
  47. }
  48. }
  49.  
  50. void drukuj_wek (double *WEK, int n){
  51. for (int i=0; i<n ; i++){
  52. cout<<WEK[i]<<endl;
  53. }
  54. }
  55. void kasuj (int **TAB,int n){
  56. for(int i=0; i<n; i++){
  57. delete []TAB[i];
  58. }
  59. }
  60.  
  61. void kasuj_wek (double *WEK,int n){
  62. delete []WEK;
  63. }
  64.  
  65.  
  66. int main(){
  67. int n;
  68. cout<<"Podaj rozmiar tablicy: ";
  69. cin>>n;
  70. srand(time(NULL));
  71. int **A=tworz_tab(n);
  72. int **B=tworz_tab(n);
  73. wypelnij(A,n,0,10);
  74. wypelnij(B,n,0,10);
  75. drukuj(A,n);
  76. cout<<endl;
  77. drukuj(B,n);
  78. cout<<endl;
  79.  
  80. double *SR1,*SR2;
  81. SR1= new double [n];
  82. SR2= new double [n];
  83. srednia_wek(A,n,SR1);
  84. srednia_wek(B,n,SR2);
  85. drukuj_wek(SR1,n);
  86. cout<<endl;
  87. drukuj_wek(SR2,n);
  88.  
  89. kasuj(A,n);
  90. kasuj(B,n);
  91. kasuj_wek(SR1,n);
  92. kasuj_wek(SR2,n);
  93.  
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement