English, asked by akanshasharmaflyingh, 6 months ago

write a program to find the maximal product of any quadruplet for input array a[]​

Answers

Answered by poojan
29

Language using: Python Programming.

Using a list for taking a list of elements. The list acts just like an array but taking in the data of multiple types.

For forming a quadruplet, the array should consist a minimum of 4 elements

Program:

no_of_elements=int(input())

l=list(map(int, input().split(', ')))

l= sorted(l)[::-1]

print("The maximal product of any in any quadruplet in the array taken is: {0}".format(l[0]*l[1]*l[2]*l[3]))

Input:

5

10, 5, 1, 4, 20

Output:

4000

Explanation:

First, we will take the list range and then input the elements into the list. Once done, we will sort it in ascending order using sorted() method, and then, [::-1] this operation will reverse the ascending ordered array, changing it into descending order.

So, now, we have the maximum 4 elements in the first 4 indices 0 to 3, and we access them, apply the product, and print the output.

Learn more:

1) Printing all the palindromes formed by a palindrome word.

brainly.in/question/19151384

2) Indentation is must in python. Know more about it at :

brainly.in/question/17731168

Similar questions