### number sequence problem

I've been trying this number sequence problem for a while now.
The program is supposed to test for numbers that are divisible by 2,3, and 5. Then the 1501st number should be outputted.

Here's what I have, what am I doing wrong?
 ``1234567891011121314`` `````` int x = 1, y = 2, z = 3, i=5; for(x = 1; x <=1501; x++) { while(x % y == 0){ x /= y; } while(x % z == 0){ x/=z; } while(x % i == 0){ x/=i; } if (x == 1) cout << x;``````
Last edited on
x is never going to get higher than 1 because of how you have your program set up. Here, try this:

 ``12345678910111213141516`` ``````int x = 1, y = 2, z = 3, a = 5; for(int i = 1; x <=1501; ++x) { if(x % y == 0){ x /= y; } if(x % z == 0){ x/= z; } if(x % i == 0){ x/= a; } if (i == 1501) cout << "1501st number is: "<< x; x++;``````

I'm not sure if that is what you wanted though, you'd have to be more specific about your problem
 `` `` `` std::cout << "The 1501st number is " << 30*1501;``

Though , this is what you are trying to do .
 ``1234567`` ``````int x=2,y=3,z=5,i = 1; for(int n = 0;n<1501;++i) { if(!(i%x || i%y || i%z)) //de morgan's law : a' and b' = (a or b)' ++n; } cout << i;``````

Hope that helps.
Last edited on
I tried what Gaius suggested and i only get a blank command prompt when i compile it?

Although akn your solution works I thank you for that, when i try what gaius suggested I just get a blank cmd prompt.

Just wondering why that happens.
Last edited on
Woops... looks like I forgot to replace the x's in the for loop:

Change this
`(int i = 1; x <=1501; ++x)`

to this
`(int i = 1; i <=1501; ++i)`

But the result is probably not what you wanted.
Just go with a k n's code
Last edited on
Topic archived. No new replies allowed.