Answer to Question #22988 in C++ for gene

Question #22988
write a C program to find and print each sequence of consecutive
positive integers whose sum is equal to 1,000,000.
1
Expert's answer
2013-01-28T09:39:27-0500
#include <conio.h>
#include <stdio.h>

void find_sequence(int first_term, int sum)
{
int k;
int term_count = 1;
int arithmetic_series;

while (1)
{
arithmetic_series = term_count * (first_term * 2 + term_count - 1) / 2;
if (arithmetic_series > sum)
break;

if (arithmetic_series == sum)
{
for (k = 0; k < term_count; k++)
printf("%d, ", first_term + k);
printf("\n\n\n");
}
term_count++;
}
}

int main()
{
int n;
for (n = 1; n <= 1000000; n++)
find_sequence(n, 1000000);
_getch();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS