60 384
Assignments Done
98,1%
Successfully Done
In April 2018

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.
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;
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions