Jz-c-41-plus

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.