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?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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;
x is never going to get higher than 1 because of how you have your program set up. Here, try this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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