Finding the Location of Two Elements with a Sum of 100 in an Array of 3 Elements

  • Topic: Comp Sci 
  • Thread starter Thread starter congo19
  • Start date Start date
  • Tags Tags
    Array Elements Sum
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
1 reply · 2K views
congo19
Messages
1
Reaction score
0
I have an array of 3 known elements.I know that 2 elements of them have the sum of 100 and I need to find the location of the two elements which have this sum
ex.
A[3]
5 25 75
the solution for this prob.
is second & third location

Thanks,
 
Physics news on Phys.org
In this case, there are only 3 possiblities, A[0] + A[1] or A[0] + A[2] or A[1] + A[2].

For a more generic solution, you could use a double loop to handle an array with N elements. I don't know if this will be a later assignment for your homework.