Answer to Question #274508 in Python for Holik

Question #274508

10. Given the real numbers x, y (x (y)


Substitute for the sum, and the largest multiplied by a multiple

1
Expert's answer
2021-12-04T12:12:51-0500
# Python program to check if there exists a pair
# in array whose sum results in x.

   
# Function to find and print pair

def chkPair(A, size, x) :


    for i in range (0, size - 1) :


        for j in range (i + 1, size):


            if (A[i] + A[j] == x) :


                print("Pair with a given sum " , x , " is (" , A[i] , ", " , A[j] , ")")


   

                return True


    return False


   
# Driver code

A = [0, -1, 2, -3, 1]


x = -2


size = len(A)

 

if (chkPair(A, size, x)) :


    print("Valid pair exists")

 

else :


    print("No valid pair exists for " , x )

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