HackerRank C- Milk Man and His Bottles




A Milkman serves milk in packaged bottles of varied sizes. The possible size of the bottles are {1, 5, 7 and 10} litres. He wants to supply the desired quantity using as fewer bottles as possible irrespective of the size. Your objective is to help him find the minimum number of bottles required to supply the given demand for milk.



  1. #include <stdio.h>
  2. int main()
  3. {
  4. int n,b=0,i,m,s=0;
  5. scanf("%d",&m);
  6. for( i=0;i<m;i++)
  7. {
  8. scanf("%d",&n);
  9. b=n/10;
  10. n=n%10;
  11. s=s+b;
  12. b=0;
  13. b=n/7;
  14. n=n%7;
  15. s=s+b;
  16. b=0;
  17. b=n/5;
  18. n=n%5;
  19. s=s+b;
  20. b=0;
  21. b=n/1;
  22. s=s+b;
  23. printf("%d\n",s);
  24. s=0;
  25. b=0;
  26. }
  27. return 0;
  28. }




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube