fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int arr[] = {0, 3, 6, 9, 12, 14, 18, 20, 22, 25, 27};
  5. int size = sizeof(arr) / sizeof(arr[0]);
  6. int n = 4; // Rotate by 4 positions
  7.  
  8. printf("The given array is:\n");
  9. for (int i = 0; i < size; i++) {
  10. printf("%d ", arr[i]);
  11. }
  12. printf("\n");
  13.  
  14. printf("From %dth position the values of the array are:\n", n);
  15. for (int i = n; i < size; i++) {
  16. printf("%d ", arr[i]);
  17. }
  18. printf("\n");
  19.  
  20. printf("Before %dth position the values of the array are:\n", n);
  21. for (int i = 0; i < n; i++) {
  22. printf("%d ", arr[i]);
  23. }
  24. printf("\n");
  25.  
  26. printf("After rotating from %dth position the array is:\n", n);
  27. for (int i = n; i < size; i++) {
  28. printf("%d ", arr[i]);
  29. }
  30. for (int i = 0; i < n; i++) {
  31. printf("%d ", arr[i]);
  32. }
  33. printf("\n");
  34.  
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
The given array is:
0 3 6 9 12 14 18 20 22 25 27 
From 4th position the values of the array are:
12 14 18 20 22 25 27 
Before 4th position the values of the array are:
0 3 6 9 
After rotating from 4th position the array is:
12 14 18 20 22 25 27 0 3 6 9