Given three integers, your task is to obtain the maximum value possible by placing appropriately Addition operator, multiplication operator and brackets between the numbers.
For Example:
If a=5,b=4,c=3
Then the possible combinations are:
a*b*c, gives 60
a*(b+c), gives 35
a+b*c, gives 17
a*b+c, gives 23
a+b+c, gives 12
(a+b)*c, gives 27
So, the output is 60, which is the maximum possible value.
Method 1:
Implementation:
For Example:
If a=5,b=4,c=3
Then the possible combinations are:
a*b*c, gives 60
a*(b+c), gives 35
a+b*c, gives 17
a*b+c, gives 23
a+b+c, gives 12
(a+b)*c, gives 27
So, the output is 60, which is the maximum possible value.
Method 1:
Implementation:
#include<stdio.h>
/*Function to return the maximum among a & b */
int getmax ( int a, int b )
{
      return a > b ? a : b;
} 
int main()
{
      int x, y, z, max;
      
      /* Getting the First number from the user */
      scanf ( " %d ", &x ); 
      /* Getting the Second number from the user */
      scanf ( " %d ", &y ); 
      /* Getting the Third number from the user */
      scanf ( " %d ",&z ); 
      /*There are 6 possibilities of placing four operators between three numbers (brackets inclusive)*/
      max = x * y * z;
     
     /*Update everytime maximum value to the "max" variable*/
      max = getmax ( max, ( x * ( y + z ) ) ); 
      max = getmax ( max, ( x + y * z ) );
      max = getmax ( max, ( x * y + z ) );
      max = getmax ( max, x + y + z );
      max = getmax ( max, ( x + y ) * z );
      /*Print the maximum value obtained by placing the operators between the operands*/
      printf ( " %d ", max ); 
 
      return 0;
}