Answer to Question #284964 in Python for Pravin

Question #284964

Given an unsorted integer array, find out the pair whose sum is the given no.

        Example : {3,12,4,7,10,8}, No => 22, So pair is {12,10} 
1
Expert's answer
2022-01-05T16:25:21-0500
No = 22
nums = [3,12,4,7,10,8]
Flag=0

for i in range(len(nums) - 1):
    for j in range(i + 1, len(nums)):
        if(nums[i] + nums[j] == No):
            Flag=1
            print('Pair: ', (nums[i], nums[j]))
if(Flag==0):
    print('Pair not found')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS