fork download
  1. #include <iostream>
  2.  
  3. void shift_arr_elem(int * arr, int arrSize, int shift)
  4. {
  5. int realShift = 0;
  6. if (shift > arrSize)
  7. realShift = shift - arrSize * (shift/arrSize);
  8. else
  9. realShift = shift;
  10.  
  11.  
  12. for (int i = 0, temp = 0; i < realShift; ++i)
  13. {
  14. temp = arr[0];
  15.  
  16. for (int j = 0; j < arrSize-1; ++j)
  17. arr[j] = arr[j+1];
  18.  
  19. arr[arrSize-1] = temp;
  20. }
  21. }
  22.  
  23. void show_array(int * arr, int arrSize)
  24. {
  25. for (int i = 0; i < arrSize; ++i)
  26. std::cout << arr[i] << " ";
  27. }
  28.  
  29. int main()
  30. {
  31. const int ARR_SIZE = 4;
  32. int arr[ARR_SIZE] = {11, 22, 33, 44};
  33. shift_arr_elem(arr, ARR_SIZE, 2);
  34. show_array(arr, ARR_SIZE);
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
33 44 11 22