# 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.

positive integers whose sum is equal to 1,000,000.

Expert's answer

#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;

}

#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;

}

## Comments

## Leave a comment