Home »
Ruby Tutorial »
Ruby Programs
Ruby program to merge two integer arrays without using library function
Last Updated : December 15, 2025
Problem Solution
In this program, we will create two arrays of integers and then we will merge both arrays without using the library function.
Program/Source Code
The source code to merge two integer arrays without using the library function is given below. The given program is compiled and executed successfully.
# Ruby program to merge two integer arrays without
# using library function
arr1 = [10,20,30,40,50];
arr2 = [60,70,80];
arr3 = Array.new(8);
count=0;
count1=0;
while(count<8)
if(count<arr1.size)
arr3[count]=arr1[count];
else
arr3[count]=arr2[count1];
count1=count1 + 1;
end
count = count + 1;
end
print "Merged array: \n";
i=0;
while(i<8)
print arr3[i]," ";
i=i+1;
end
Output
Merged array:
10 20 30 40 50 60 70 80
Explanation
In the above program, we created two arrays of integer elements. Then we merged both arrays and assigned the result to the arr3 without using the library function. After that, we printed the merged array.
Ruby Arrays Programs »
Advertisement
Advertisement