Current location - Training Enrollment Network - Mathematics courses - Examples of programming mathematics
Examples of programming mathematics
I can only provide an algorithm, the specific programming statement has been lost for too long … and you didn't say whether the numbers can be selected repeatedly …

The case of repeated selection: set the function f(x), where x is the required sum d; Set the loop I from 1 to 8 in the function body, and judge whether the statement x-i is equal to 0, if so, output I and return; If the result is greater than 0, continue to do f(x-i) and output I at the same time;

If the selection cannot be repeated: set the function f(x, a), where x is the required sum d and a is the auxiliary parameter; Set the loop I from A to 8, and judge whether the statement x-i is equal to 0, if it is, output I and return; If the result is greater than 0, continue to do f(x-i, i).