Sword Point 41st-expand: And for S continuous positive sequence: Enter a positive number s, print all and a continuous positive sequence of s (at least two numbers)
1 //============================================================================2 //Name:jz-c-41-plus.cpp3 //Author:laughing_lz4 //Version:5 //Copyright:all Right Reserved6 //Description: And a sequential positive sequence for s: Enter a positive number s and print out all successive positive sequences (at least two numbers) for S7 //============================================================================8 9#include <iostream>Ten#include <stdio.h> One using namespacestd; A - voidPrintcontinuoussequence (intSmallintbig); - the voidFindcontinuoussequence (intsum) { - if(Sum <3) - return; - + intsmall =1; - intBig =2; + intMiddle = (1+ sum)/2; A intCursum = small + big;//here cursum is actually the summation of all the numbers from small to big and at - while(Small <middle) { - if(Cursum = =sum) - printcontinuoussequence (small, big); - - while(Cursum > Sum && Small <middle) { inCursum-= small;//Update cursum value each time -small++; to + if(Cursum = =sum) - printcontinuoussequence (small, big); the } * //While (cursum <= sum && Small < middle) {//I write or not as the source AH. Clear but not concise $ //big++;Panax Notoginseng //cursum + = big; - //if (cursum >= sum) the //Break ; + // } Abig++; theCursum + = big;//Update cursum value each time + } - } $ $ voidPrintcontinuoussequence (intSmallintbig) { - for(inti = small; I <= big; ++i) -printf"%d", i); the -printf"\ n");Wuyi } the - //==================== test Code ==================== Wu voidTest (Char* TestName,intsum) { - if(TestName! =NULL) Aboutprintf"%s for%d begins: \ n", testname, sum); $ - findcontinuoussequence (sum); - } - A intMainintargcChar**argv) { +Test ("test1",1); theTest ("test2",3); -Test ("test3",4); $Test ("test4",9); theTest ("Test5", the); theTest ("Test6", -); the the return 0; -}
Jz-c-41-plus