issues
search
Deepaganesh407
/
Rotate-array
0
stars
0
forks
source link
issues
Newest
Newest
Most commented
Recently updated
Oldest
Least commented
Least recently updated
#rotate array #include <stdio.h> void rotateArray(int arr[], int n, int k) { int temp[k]; for (int i = 0; i < k; i++) { temp[i] = arr[i]; } for (int i = 0; i < n - k; i++) { arr[i] = arr[i + k]; } for (int i = 0; i < k; i++) { arr[n - k + i] = temp[i]; } } void printArray(int arr[], int n) { for (int i = 0; i < n; i++) { printf("%d ", arr[i]); } printf("\n"); } int main() { int n, k; printf("Enter the size of the array: "); scanf("%d", &n); int arr[n]; printf("Enter %d elements of the array: ", n); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } printf("Enter the number of positions to rotate: "); scanf("%d", &k); k = k % n; rotateArray(arr, n, k); printf("Array after rotation: "); printArray(arr, n); return 0; }
#1
Deepaganesh407
opened
1 month ago
1