Ruby program to reverse an array without using library function

You may have read many articles but I hope the Ruby program to reverse an array without using library function article will satisfy all your doubts. The reason for that is that I have written this article in such a way as to satisfy all your doubts.

Ruby program to reverse an array without using library function

Ruby program to reverse an array without using library function

# Ruby program to reverse an array without 
# using library function

arr = [12,45,23,39,38];
RevArray = Array.new(arr.size());
count1 = 0;
count2 = arr.size()-1;

while(count1<arr.size())
    RevArray[count1]=arr[count2];
    
    count1=count1 + 1;
    count2=count2 - 1;
end

print "Array:\n";
count1=0;
while(count1<arr.size)
    print arr[count1]," ";
    count1=count1 + 1;
end

print "\nReversed Array:\n";
count1=0;
while(count1<RevArray.size)
    print RevArray[count1]," ";
    count1=count1 + 1;
end
Array:
12 45 23 39 38 
Reversed Array:
38 39 23 45 12 

Final Words

Ruby program to reverse an array without using library function We hope all your doubts have been resolved through this article. Also if you need any information you can let us know your doubts in the comment box.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment