Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int array[] = { 2, 3, 4, 7, 10 };
- int n = 18;
- // Get smallest number
- int smallest_number = 999;
- for (int i = 0; i < length(array); i++)
- if (array[i] < smallest_number)
- smallest_number = array[i];
- // If biggest number is at the end of your array - do it backwards:
- // Do it as long (n > 0)
- for (int i = length(array) - 1; i >= 0 && n > 0; i--) {
- // Can subtract from n
- if (array[index] > n)
- continue;
- // Array value is smaller or equal 'n'
- int new_value = n - array[index];
- if (new_value > 0 && new_value < smallest_number)
- continue;
- else
- n = new_value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement