Ticker

6/recent/ticker-posts

Program for finding pair of highest product.

 

Program


arr=eval(input("enter list element"))

a=arr[0]

b=arr[1]

for i in range(0,len(arr)):

    for j in range(i+1,len(arr)):

        if (arr[i]*arr[j])>(a*b):

            a=arr[i]

            b=arr[j]

print(a,b,a*b)

Output

enter list element0,-2,-1,-4,5,-8,7,-8,8

-8 -8 64

=== Code Execution Successful ===


Example if list is 0,-2,-1,-4,5,-8,7,-8,8

So pair are

(0,-2)=0

(0,-1)=0

(0,-4)=0

(0,5)=0

(0,-8)=0

(0,7)=0

(0,-8)=0

(0,8)=0

(-2,-1)=2

(-2,-4)=8

(-2,5)=-10

(-2,-8)=16

(-2,7)=-14

(-2,-8)=16

(-2,8)=-16

(-1,-4)=4

(-1,5)=-5

(-1,-8)=8

(-1,7)=-7

(-1,-8)=8

(-1,8)=-8

(-4,5)=-20

(-4,-8)=32

(-4,7)=-28

(-4,-8)=32

(-4,8)=-32

(5,-8)=-40

(5,7)=35

(5,-8)=-40

(5,8)=40

(-8,7)=-56

(-8,-8)=64

(-8,8)=-64

(7,-8)=-56

(7,8)=56

(-8,8)=-64


Highest product of the pair is (-8,-8) that product is 64.




Post a Comment

0 Comments