Canna

Tuesday, 25 September 2018

WHEAT MERCHANT

  • Problem Description

    WHEAT MERCHANT 
    A Wheat merchant supplies wheat in packaged containers of varied sizes. The possible capacities of the containers are {1, 5, 7 and 10} kilograms.
    He wants to supply desired quantity of wheat using as less no of containers as possible irrespective of the capacity. Help him find the minimum number of containers required to supply the given demand of wheat. Use Functions in C language to make the process easy.
    Input Format:

    First line contains number of test cases N 
    Next N lines, each contain a positive integer Li which corresponds to the demand quantity of wheat.

    Output Format:
    For each input Li, print the minimum number of Containers required to fulfill the demand 



  • Test Case 1

    Input (stdin)
    1
    
    17
    
    
    Expected Output
    2
  • Test Case 2

    Input (stdin)
    0
    
    
    Expected Output
    0
  • Program
  • #include <stdio.h>
    int main()
    {
      int a,n,i,b=0;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
        scanf("%d",&a);
        if (a>10)
        {
          a=a-10;
          b++;
        }
        if(a>7)
        {
          a=a-7;
          b++;
        }
        if (a>5)
        {
          a=a-5;
          b++;
        }
        printf("%d",b);
      }
      return 0;
    }

No comments:

Post a Comment

Note: only a member of this blog may post a comment.