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