homework help

calculate all the product of the following sequence 4,8,12,16......... till the total exceeds 2400
What do you have so far?
is this correct?

#include<iostream.h>
#include<conio.h>
void main()
{
int x=4;
while(++x<=2400)
{
cout<<x;
}
getch();
}
closed account (E3h7X9L8)
this is the part of code you need
1
2
3
4
5
6
7
8
int x=8,p=4;
do
{
    p=p*x;
    x=x+4; 
}
while(p<=2400);
cout<<p;
Last edited on
I think the code would be clearer if you use a for loop. For loops aren't just for counting from 1 to N, they handle any sort of loop that has initialization, a test, and an increment:
1
2
3
4
int product = 1;
for (int factor=4; product <= 2400; factor += 4) {
    product *= factor;
}


Topic archived. No new replies allowed.