Created
November 9, 2010 08:58
-
-
Save shihongzhi/668879 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://zhedahht.blog.163.com/blog/static/25411174200732711051101/ 我是倒这过来做的 | |
#include <stdio.h> | |
void print_sequence(int small,int big) | |
{ | |
int i; | |
for(i=small;i<=big;i++) | |
printf("%d ",i); | |
printf("\n"); | |
} | |
void find_sequence(int n) | |
{ | |
int small,big,middle; | |
int sum; | |
small=1;big=2; | |
if(n<3) | |
return; | |
middle=(n+1)/2; | |
sum=small+big; | |
while(small<=middle){ | |
if(sum==n) | |
print_sequence(small,big); | |
while(sum<n){ | |
big++; | |
sum+=big; | |
if(sum==n){ | |
print_sequence(small,big); | |
} | |
} | |
sum-=small; | |
small++; | |
} | |
} | |
int main() | |
{ | |
find_sequence(15); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment