Skip to content

Instantly share code, notes, and snippets.

@shihongzhi
Created November 9, 2010 08:58
Show Gist options
  • Save shihongzhi/668879 to your computer and use it in GitHub Desktop.
Save shihongzhi/668879 to your computer and use it in GitHub Desktop.
//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