Guest User

Untitled

a guest
Nov 17th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. int n = 6, s =25, i = 0;
  6. int a[] = {1,2,4,8,16,32};
  7. int b[n];
  8. i = n;
  9. while(i >= 1) {
  10. if (s >= a[i-1]){
  11. b[i-1] = 1;
  12. s -= a[i-1];
  13. } else {
  14. b[i-1] = 0;
  15. }
  16. i--;
  17. }
  18.  
  19. for(int i = 0; i < n; i++) {
  20. if (b[i] == 1) {
  21. printf("%d ", a[i]);
  22. }
  23. }
  24.  
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment