A non-empty array A consisting of N numeric values is
given.
The product of quadruplet (P, Q, R, S) equates to A[P] *
A[Q] * A[R] * A[S]
(O SP<Q <R<S< N).
For example, array A such that:
A[2] = 2
A[3] = -2 A[4] = 5
A[0] = -3
A[5] = 6
A[1] = 1
A[6] = 1
. (0, 1, 2, 3), product is -3*1*2* -2 = 12
• (1,2,4,5), product is 1*2*5*6 = 30
• (2, 4,5,6), product is 2*5*6*1 = 60
60 is the product of quadruplets (2, 4,5, 1), which is
ximal.
Answers
Answer:
In Java
Step-by-step explanation:
import java.util.*;
public class HelloWorld{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
float max_product = 1;
for(int i = 0; i<n; i++)
{
arr[i] = sc.nextInt();
}
for (int i = 0; i < n - 3; i++)
for (int j = i + 1; j < n - 2; j++)
for (int k = j + 1; k < n - 1; k++)
for (int l = k + 1; l < n; l++)
max_product = Math.max(max_product, arr[i] * arr[j] * arr[k] * arr[l]);
System.out.println(max_product);
}
}
Answer:
IN PYTHON
Step-by-step explanation:
a=int(input("Enter count of values you are going to insert:"))
c=[]
if(a<=3):
print("invalid input")
else:
print("Enter", a, "numbers:")
for i in range(0,a):
d=int(input())
c.append(d)
for i in range(0, a - 3):
for j in range(i + 1, a - 2):
for k in range(j + 1, a - 1):
for l in range(k + 1, a):
maxi = 0
m = c[i] * c[j] * c[k] * c[l]
if (m > maxi):
maxi = m
print(maxi)