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.
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.
Output:
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.
need an explanation for this answer? contact us directly to get an explanation for this answer