#include "stdafx.h" void reverse(int * arr, int left, int right) { for(;left<right;left++,right--) { int temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; } } void shift(int * arr, int len, int k) { reverse(arr,0,len-k-1); reverse(arr,len-k,len-1); reverse(arr,0,len-1); } int _tmain(int argc, _TCHAR* argv[]) { int arr[5] = {1,2,3,4,5}; shift(arr,5,2); for(int i=0;i<5;i++) printf("%d ",arr[i]); return 0; }