Just some idea's:
Code:
#define MAX 100
int answer[MAX] = { 0 };
int main(void) {
get your sum number, here
getSeries(sum);
printf("\n\n\t\t Program Complete - Press Enter to Continue");
gar = getchar(); gar++; //holds the console window open
return 0;
}
int lo, hi, i, j, tally, count; //sum came into the function on the parameter set
say sum is 10
hi = sum / 2 + 2;
//10/2 = 4, so add one, but one can be part of a series, so add one more
lo = 1;
while(lo < hi) {
set tally to zero, here
/* idea here is to start at the low end, and add up the numbers, into tally,
until tally is > target.
*/
for(i = lo, j = 0; tally < sum; i++) {
tally += i;
answer[j++] = i;
if( tally == sum) {
print the whole set of numbers in answer[], that have made up tally
count++; //count the sets that meet the criteria.
}
}
lo++;
reset the answer[] here, to all zero's.
}
This won't solve your problem. Just a step in the right direction.
Edit: This thought worked out well. Interestingly, the only numbers w/o at least one series of consecutive integers
equaling their sum, have an odd coincidence with computers:
1, 2, 4, 8, 16, 32, 64, 128, 256, 512 where Sum = 1 - 1,000.