I need some help -
At the end of a for loop, I need to set an original value to the next multiple of the value.
This is what I have so far -
int originalNumber = 1;
for (int i = 1; i <= 10000; i++) {
originalNumber *= i;
}
However, this code will not find the multiples of 1; as the multiples of 1 should be (1, 2, 3, 4, 5, 6, ... ...)
This code that I have written will be (1, 1, 2, 6, 24) etc;
What is a good way to get the multiples (inside of the loop)?
You don't need to change originalNumber
at all - just multiply i
by originalNumber
:
int originalNumber = 1;
for (int i = 1; i <= 10000; i++) {
int multiple = originalNumber * i;
// Use multiple however you want to
}
To get all the multiples of 2, you'd set originalNumber
to 2, etc.
See more on this question at Stackoverflow