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]
(0 P<Q R S < N).
For example, array A such that:
A[0] = -3
A[6] = 1
A[1] = 1
A[2] = 2
A[3] = -2
A[4] = 5
A[5] = 6
(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 maximal.
Your goal is to find the maximal product of any quadruplet for
input Array A[]
Write an efficient algorithm for the following assumntions:
Answers
Answer:
#include <stdio.h>
void main ()
{
int number[30];
int i, j, a, n;
printf("Enter the value of N\n");
scanf("%d", &n);
printf("Enter the numbers \n");
for (i = 0; i < n; ++i)
scanf("%d", &number[i]);
/* sorting begins ... */
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (number[i] < number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
if(n<3){
printf("Wrong");
}else
{
printf("The numbers arranged in descending order are given below\n");
int sum=1;
for (i = 0; i < n; ++i)
{
sum=number[i]*sum;
}
printf("%d",sum);
}
}
Explanation: