Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. void fill_array(int* arr, int size);
  6. void show_array(int* arr, const int size);
  7.  
  8. const int plus_size = 5;
  9.  
  10. int main()
  11. {
  12.     int size = 1;
  13.     const int new_size = 1;
  14.  
  15.     int *arr = new int[size];
  16.  
  17.     int k = 0;
  18.     int enter_value = 0;
  19.  
  20.     cout << "Enter number 1-5: " << endl;
  21.     for (int a = 0; a < size; a++)
  22.     {
  23.         cout << "[" << a << "]: ";
  24.         cin >> enter_value;
  25.  
  26.         if (enter_value == 0)
  27.         {
  28.             break;
  29.         }
  30.  
  31.         arr[a] = enter_value;
  32.  
  33.         if (a == size - 1)
  34.         {
  35.             size += new_size;
  36.  
  37.             int *arr2 = new int[size];
  38.             for (int a = 0; a < size; a++)
  39.             {
  40.                 arr2[a] = arr[a];
  41.             }
  42.  
  43.             show_array(arr2, size - new_size);
  44.             delete[] arr;
  45.  
  46.             arr = arr2;
  47.         }
  48.     }
  49.  
  50.     show_array(arr, size - new_size);
  51.  
  52.     system("pause");
  53.     return 0;
  54. }
  55.  
  56. void fill_array(int* const arr, const int size)
  57. {
  58.     for (int i = 0; i < size; i++)
  59.     {
  60.         arr[i] = rand() % 10;
  61.     }
  62. }
  63.  
  64. void show_array(int* const arr, const int size)
  65. {
  66.     for (int i = 0; i < size; i++)
  67.     {
  68.         cout << arr[i] << " ";
  69.     }
  70.  
  71.     cout << endl;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement