Write a program that will store 7 integers (entered by the user) into an array called list1. Next, prompt the user for 5 integers and put them into an array called list2. Now, list all of the numbers that are in BOTH lists by calling a function called inBoth and passing list1 and list2 to that function.
I understand how to create the 2 arrays, Im just really lost on how to program the function that will compare them and figure out if there are any of the same numbers.
it has to look like this:
List 1
------
Enter an integer: 4
Enter an integer: 2
Enter an integer: 7
Enter an integer: 1
Enter an integer: 5
Enter an integer: 6
Enter an integer: 3
List 2
------
Enter an integer: 11
Enter an integer: 9
Enter an integer: 7
Enter an integer: 5
Enter an integer: 3
The numbers that are in both lists are:
3, 5, 7
and I dont know how to put that into a function and then call it.
@fg109 Yeh lol, You'd need a nested loop. Also, Works fine for me, Ive never had segmentation fault when Im just trying to compare out-of-bounds arrays. Im using vs 13, I googled around and its normal that it works. Doesnt work with vectors though.
I guess you're right. I usually don't work with out of bounds arrays so I thought that's what would happen, like with linked lists as such.
@kle5208
Here's an example of one way you can do it. You'll have to convert the code to work with arrays though, which I am sure would be a lot more trouble than doing it TarikNeaj's way. It doesn't really handle duplicates that well either.