Canteen Bill by offer

Description:

") A new Canteen is opened in IIST Campus. Since today is the opening day, the canteen owner is giving an offer, in which every student must purchase 5 items each each of cost <1,000. The offer is, student can pay any amount, but the amount paid is the result of four binary operations ( +, - , *, / ) between the cost of five items. Now your taks is to help the student save his money. NOTE: No binary operator is to be repeated. Input Input consists of five integers each seperated by spaces. Output Your output must contain an ineger satisfying the above conditions " Test Case 1 Input (stdin) 2 3 4 5 6 Expected Output 1 Test Case 2 Input (stdin) 5 9 6 4 7 Expected Output 2

Program :


#include <stdio.h>

#include <string.h>

#include <stdlib.h>

 

int main (void)

{

  long long result[24], min;

  long long a, b, c, d, e;

  int i;

 

  scanf("%lld %lld %lld %lld %lld", &a, &b, &c, &d, &e);

 

  result[0 ] = a + b - c * d / e;

  result[1 ] = a + b - c / d * e;

  result[2 ] = a + b * c / d - e;

  result[3 ] = a + b * c - d / e;

  result[4 ] = a + b / c * d - e;

  result[5 ] = a + b / c - d * e;

 

  result[6 ] = a - b + c * d / e;

  result[7 ] = a - b + c / d * e;

  result[8 ] = a - b * c + d / e;

  result[9 ] = a - b * c / d + e;

  result[10] = a - b / c + d * e;

  result[11] = a - b / c * d + e;

 

  result[12] = a * b - c + d / e;

  result[13] = a * b - c / d + e;

  result[14] = a * b + c - d / e;

  result[15] = a * b + c / d - e;

  result[16] = a * b / c + d - e;

  result[17] = a * b / c - d + e;

 

  result[18] = a / b - c * d + e;

  result[19] = a / b - c + d * e;

  result[20] = a / b * c - d + e;

  result[21] = a / b * c + d - e;

  result[22] = a / b + c * d - e;

  result[23] = a / b + c - d * e;

 

  min = 9223372036854775807;

 

  for(i = 0; i < 24; i++){

    if(result[i] > 0 && result[i] < min)

  min = result[i];

  }

  printf("%lld", min);

  return 0;

}