array

If I am given an array which contains 10 positive intergers, how to write in Unix shell returning any two numbers which sum up as 10, how about in perl which is easier
Thanks

Probably an easier way, but this will work:

#!/usr/bin/perl

@nums = qw{1 1 3 2 4 5 6 3 3 1};

# each integer has only one other integer that can be added to it to get 10

foreach (@nums) {
   $diff = 10 - $_;
   foreach $i(@nums) {
      if ($i == $diff) {
         print "$_ and $i add up to 10\n";
      }         
   }    
}

Just change the numbers inside the list to play around with it.

But I would assume I don't know any intergers in the array
so I need to make sure no intergers is last than 10, if so, the game is over,
if not, we can use double loop? how about if we don't know how many numbers in array ( not necessarily 10)

You are not explaining your situation very well. Have you written any code yet to try and figure this out? How is the array going to be populated with numbers? Can there be duplicates in the array so you can have combinations like 5 + 5 = 10? Can there be many duplicates in the array so you can have something like 5 + 5 = 10 many times? Try and clarify your question or expect answers that are very general in nature.