ADVERTISEMENT
ADVERTISEMENT

Ruby program to merge two integer arrays without using library function

Ruby Example: Write a program to merge two integer arrays without using library function.
Submitted by Nidhi, on January 22, 2022

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


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.