Practice

Cyclic Right Shift



Write a function with the header

 void cyclicRightShift (char s[ ], int n)

that shifts each character in the null-terminated string s[ ] by n elements to the right and moves each character that shifts beyond the end of the string to the beginning of the string.  The character immediately to the right of element i is element i+1.

The following calls

 char s[ ] = "abcdef";
 cyclicRightShift( s, 1 );
 printf("%s\n", s );
 cyclicRightShift( s, 2 );
 printf("%s\n", s );
 cyclicRightShift( s, 3 );
 printf("%s\n", s );

display respectively

 fabcde
 defabc
 abcdef
  Top  Go Back to the Top of this Page



  Designed by Chris Szalwinski   Copying From This Site