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

AI Thread Summary
To find the locations of two elements in an array of three that sum to 100, evaluate the three possible pairs: A[0] + A[1], A[0] + A[2], and A[1] + A[2]. In the provided example, the elements 25 and 75 at the second and third positions meet this criterion. For larger arrays, a double loop can be implemented to check all combinations of elements. This approach allows for a more scalable solution beyond the initial three elements. The discussion emphasizes the simplicity of the problem while suggesting methods for broader applications.
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.
 

Similar threads

Replies
21
Views
3K
Replies
5
Views
2K
Replies
13
Views
3K
Replies
12
Views
1K
Replies
1
Views
2K
Replies
1
Views
6K
Replies
2
Views
2K
Replies
15
Views
2K
Back
Top