Input a positive number N, and output all sequences that are n continuous positive numbers.
For example, input 15, because 1 + 2 + 3 + 4 + 5 = 4 + 5 + 6 = 7 + 8 = 15, therefore, three consecutive sequences 1-5, 4-6, and 7-8 are output.
This question is still relatively simple. It starts from the beginning. If it is less, it will be added later. If it is more, it will be reduced later.CodeAs follows:
# Include <iostream> using namespace STD; void print (const Int & START, const Int & End) {cout <"="; for (INT I = start; I <= end; I ++) {cout <I; If (end! = I) cout <'+' ;}} void printconsum (int n) {cout <n; int start = 1, sum = 0; For (INT I = 1; I <= (n + 1)/2; I ++) {sum + = I; If (sum = N) {print (start, I ); sum-= start ++;} while (sum> N) {sum-= start ++;} If (sum = N) {print (start, I ); sum-= start ++ ;}}cout <Endl ;}int main () {printconsum (15); Return 0 ;}