Advertisement
Petro_zzz

lesson9

Sep 10th, 2022
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. using namespace std;
  4.  
  5. const int sz1 = 5;
  6. const int sz2 = 6;
  7.  
  8. void genArray(int arr[sz1][sz2],           
  9.               const int min,
  10.               const int max) {
  11.     for (int k = 0; k < sz1; ++k) {
  12.         for (int n = 0; n < sz2; ++n) {
  13.             arr[k][n] = min + rand() % (max - min + 1);
  14.         }
  15.     }
  16. }
  17.  
  18. void showArr(const int arr[sz1][sz2]){
  19.     for (int k = 0; k < sz1; ++k) {
  20.         for (int n = 0; n < sz2; ++n) {
  21.             cout << arr[k][n] << "\t";
  22.         }
  23.         cout << endl;
  24.     }
  25.  
  26.     int buff[sz1 + 1][sz2 + 1]{};
  27.     for (int k = 0; k < sz1; ++k) {    
  28.         for (int n = 0; n < sz2; ++n) {
  29.             buff[k][n] = arr[k][n];
  30.             buff[k][sz2] += arr[k][n];
  31.             buff[sz1][n] += arr[k][n];
  32.             //buff[sz1][sz2] += buff[sz1][n];
  33.         }
  34.         buff[sz1][sz2] += buff[k][sz2];
  35.     }
  36.  
  37.     cout << endl;
  38.     for (int k = 0; k < sz1+1; ++k) {
  39.         for (int n = 0; n < sz2+1; ++n) {
  40.             if (n == sz2)
  41.                 cout << "|\t";
  42.             cout << buff[k][n] << "\t";
  43.         }      
  44.         cout << endl;
  45.         if (k == sz1-1)
  46.             cout << "---------------------------------------------------------\n";
  47.     }
  48. }
  49.  
  50. double qube(const double x) {
  51.     return x * x * x;
  52. }
  53.  
  54. int search(const int arr[], const int arr2[], const int sz1, const int sz2) {
  55.     bool flag;
  56.     for (int k = 0; k < sz1-sz2;k++) {
  57.         if (arr[k] == arr2[0]) {
  58.             flag = true;
  59.             for (int n = 1; n < sz2; n++) {
  60.                 if (arr[k + n] != arr2[n]) {
  61.                     flag = false;
  62.                     break;
  63.                 }                   //return -1;
  64.             }
  65.             if(flag)
  66.                 return k;
  67.         }
  68.     }
  69.     return -1;
  70. }
  71.  
  72. void solve_task2() {
  73.     const int sz1 = 9;
  74.     int arr[]{1, 2, 3, 5, 5, 6, 3, 4, 9};
  75.     const int sz2 = 2;
  76.     int arr2[]{ 3, 4 };
  77.     cout << "pos: " << search(arr, arr2, sz1, sz2) << endl;
  78.  
  79. }
  80.  
  81.  
  82. void solve_task1() {
  83.     int arr[sz1][sz2];
  84.     srand(time(NULL)); 
  85.     genArray(arr,0, 10);
  86.     showArr(arr);
  87. }
  88.  
  89. void test_dinamicarray(int n){
  90.     //double x[3]{ 3.141592, 0.5, 0.25};
  91.     //cout << x << " " << &(x[0]) << " " << &(*x) << endl;
  92.     //cout << pVal << " " << pVal[1] << endl;
  93.     double* pVal = new double[n]; /// x
  94.     int k = 0;
  95.     while(k < n){
  96.         pVal[k] = k*sqrt(2);
  97.         k++;
  98.     }
  99.     //delete[] pVal;   
  100.     //double y = 2.3;
  101.     //pVal = &y;
  102.     for (int k = 0; k < 1; k++) {
  103.         cout << pVal[k] << " ";
  104.     }
  105.  
  106.     cout << endl;
  107.     cout << "size: " << _msize(pVal) / sizeof(pVal[0]) << endl;
  108.  
  109.  
  110.     //cout << endl;
  111.     delete[] pVal;
  112.  
  113.    
  114.    
  115.    
  116. }
  117.  
  118. int main(){
  119.     //solve_task1();
  120.     //solve_task2();
  121.     test_dinamicarray(4);
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement