Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main() {
- int n = 6, s =25, i = 0;
- int a[] = {1,2,4,8,16,32};
- int b[n];
- i = n;
- while(i >= 1) {
- if (s >= a[i-1]){
- b[i-1] = 1;
- s -= a[i-1];
- } else {
- b[i-1] = 0;
- }
- i--;
- }
- for(int i = 0; i < n; i++) {
- if (b[i] == 1) {
- printf("%d ", a[i]);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment