×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

Ruby program to cyclically permutes the elements of the array

Last Updated : December 15, 2025

Problem Solution

In this program, we will create an array of integers and then we will cyclically permute the elements of the array and print the result.

Program/Source Code

The source code to cyclically permute the elements of the array is given below. The given program is compiled and executed successfully.

# Ruby program to Cyclically Permute the 
# elements of array

arr = [12,69,49,87,68];

print "Array elements before Cyclically Permutation: \n";
i=0;
while(i<5)
    print arr[i]," ";
    i=i+1;
end

i=0;
t = arr[0];
while(i<5)
    if(i==4)
        arr[i]=t;
    else
        arr[i]=arr[i + 1];
    end
    i = i + 1;
end
        
print "\nArray elements after Cyclically Permutation: \n";
i=0;
while(i<5)
    print arr[i]," ";
    i=i+1;
end

Output

Array elements before Cyclically Permutation: 
12 69 49 87 68 
Array elements after Cyclically Permutation: 
69 49 87 68 12 

Explanation

In the above program, we created an array of integer elements. Then we cyclically permutated the elements of the array. After that, we printed the result.

Ruby Arrays Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.