Search
 
SCRIPT & CODE EXAMPLE
 

CPP

cyclic array rotation in cpp

// Array Rotations

#include <bits/stdc++.h>

using namespace std;

void arrayRotation(int arr[], int n){
    int last = arr[n-1];
    for(int i=n-1;i>0;i--)
    arr[i] = arr[i-1];
    arr[0] = last;
}

int main(){
    int n,i,turns;
    // size of the array
    cin >> n;
    
    int arr[n];
    for(i=0;i<n;i++)
    cin >> arr[i];

    // Number of times the array is to be rotated
    cin >> turns;

    for(i=0;i<turns;i++)
    arrayRotation(arr,n);

    for(i=0;i<n;i++)
    cout << arr[i] << " ";

    return 0;

}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ Attribute Parser 
Cpp :: how creat matrix column in c++ 
Cpp :: how to copy vector to another vector in c++ 
Cpp :: convert wchar_t to to multibyte 
Cpp :: convert ascii char value to hexadecimal c++ 
Cpp :: disallowcopy c++ 
Cpp :: Integer Moves codeforces solution 
Cpp :: loop execution decending order in c 
Cpp :: C++ Program to Find the Range of Data Types using Macro Constants 
Cpp :: cmake g++ address sanitizer 
Cpp :: initialize 2d vector c++ 
Cpp :: what is the default include path in ubuntu c++ 
Cpp :: size of string c++ 
Cpp :: intersection between vector c++ 
Cpp :: Ninja c++ 
Cpp :: inline function in cpp 
Cpp :: int cpp 
Cpp :: how to run cpp using gcc vscode 
Cpp :: DSA 2. Complexity Analysis Google drive Educative excellent courses!!!! [Educative.io] Competitive Programming in C++ The Keys to Success 
Cpp :: stl map remove item 
Cpp :: how to sort string array in c++ 
Cpp :: Shell-Sort C++ 
Cpp :: even and odd numbers 1 to 100 
Cpp :: kmp c++ 
Cpp :: c++ square and multiply algorithm 
Cpp :: read a file line by line c++ struct site:stackoverflow.com 
Cpp :: the amount of input is unknown 
Cpp :: c++ to c converter tool 
Cpp :: c++ copy vector 
Cpp :: increment integer 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =