Q:

Ruby program to find the uncommon elements from two arrays

0

In this program, we will find the un-common elements of two arrays using the "-" operator and print the result.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to find the uncommon elements from two arrays is given below. The given program is compiled and executed successfully.

# Ruby program to find the uncommon elements 
# from two arrays

arr1 = ["RAM","KRISHNA","SHIV","GANESH"];
arr2 = ["KRISHNA","RAM"];

arr3 = arr1 - arr2;
 
print "Uncommon array elements:\n#{arr3}";

Output:

Uncommon array elements:
["SHIV", "GANESH"]

Explanation:

In the above program, we created 2 arrays arr1arr2. Then we found the uncommon elements from arrays using the "-" operator and printed the result.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now