C++ Program to Split the array and add the first part to the end Last Updated : 05 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report There is a given an array and split it from a specified position, and move the first part of array add to the end. Examples: Input : arr[] = {12, 10, 5, 6, 52, 36} k = 2 Output : arr[] = {5, 6, 52, 36, 12, 10} Explanation : Split from index 2 and first part {12, 10} add to the end . Input : arr[] = {3, 1, 2} k = 1 Output : arr[] = {1, 2, 3} Explanation : Split from index 1 and first part add to the end. CPP // CPP program to split array and move first // part to end. #include <bits/stdc++.h> using namespace std; void splitArr(int arr[], int n, int k) { for (int i = 0; i < k; i++) { // Rotate array by 1. int x = arr[0]; for (int j = 0; j < n - 1; ++j) arr[j] = arr[j + 1]; arr[n - 1] = x; } } // Driver code int main() { int arr[] = { 12, 10, 5, 6, 52, 36 }; int n = sizeof(arr) / sizeof(arr[0]); int position = 2; splitArr(arr, 6, position); for (int i = 0; i < n; ++i) printf("%d ", arr[i]); return 0; } Output: 5 6 52 36 12 10 Please refer complete article on Split the array and add the first part to the end for more details! Comment More infoAdvertise with us Next Article How to Take Input in Array in C++? K kartik Follow Improve Article Tags : C++ Practice Tags : CPP Similar Reads Get first and last elements from Array and Vector in CPP Given an array, find first and last elements of it. Input: {4, 5, 7, 13, 25, 65, 98} Output: First element: 4 Last element: 98 In C++, we can use sizeof operator to find number of elements in an array. CPP // C++ Program to print first and last element in an array #include <iostream> using nam 2 min read How to split a string in C/C++, Python and Java? Splitting a string by some delimiter is a very common task. For example, we have a comma-separated list of items from a file and we want individual items in an array. Almost all programming languages, provide a function split a string by some delimiter. In C: // Splits str[] according to given delim 7 min read strtok() and strtok_r() functions in C with examples C provides two functions strtok() and strtok_r() for splitting a string by some delimiter. Splitting a string is a very common task. For example, we have a comma-separated list of items from a file and we want individual items in an array. strtok() Function The strtok() method splits str[] according 5 min read How to Take Input in Array in C++? Arrays in C++ are derived data types that can contain multiple elements of the same data type. They are generally used when we want to store multiple elements of a particular data type under the same name. We can access different array elements using their index as they are stored sequentially in th 3 min read C++ Program For Iterative Quick Sort Quicksort also known as partition-exchange sort is a divide-and-conquer sorting algorithm that works by selecting a pivot element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot element. The sub-arrays can then 4 min read C++ Program For Radix Sort Radix Sort is a sorting technique in which we sort the elements by processing each and every digit of that element. It is not a comparison-based sorting algorithm which means we do not compare the elements in a radix sort in order to sort them. Here, we apply counting sort to every digit of an eleme 5 min read Like