Advertisement
BM_R1KO

Untitled

Feb 7th, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using std::cout;
  4.  
  5. #define SIZE 5
  6.  
  7. void ShiftArrayValues(int *pArray);
  8. void PrintArrayValues(int *pArray);
  9.  
  10. int main()
  11. {
  12.     int *pArray = new int[SIZE];
  13.  
  14.     for (int i = 0; i < SIZE; ++i)
  15.     {
  16.         *(pArray + i) = rand() % 10;
  17.         cout << i << " = " << *(pArray + i) << "\n";
  18.     }
  19.  
  20.     for (int i = 0; i < 5; ++i)
  21.     {
  22.         cout << "\n \n";
  23.         ShiftArrayValues(pArray);
  24.         PrintArrayValues(pArray);
  25.     }
  26.  
  27.     delete[] pArray;
  28.  
  29.     return 0;
  30. }
  31.  
  32. void ShiftArrayValues(int *pArray)
  33. {
  34.     cout << "ShiftArrayValues:\n";
  35.     int iBuffer = *pArray;
  36.     for (int i = 0; i < SIZE-1; ++i)
  37.     {
  38.         *(pArray + i) = *(pArray + i + 1);
  39.     }
  40.     *(pArray + 4) = iBuffer;
  41. }
  42.  
  43. void PrintArrayValues(int *pArray)
  44. {
  45.     for (int i = 0; i < SIZE; ++i)
  46.     {
  47.         cout << i << " == " << *(pArray + i) << "\n";
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement