I am trying to write a piece of code that will take the number let’s say 24 and get all the factors for it so it would print the numbers 1 and 24, 8 and 3, etc. I tried doing this myself however I am fairly new to using c++ so it kind of confuses me a little. I apologize if this is really easy or simple to answer. could you please show me how this could be done?
int y = 0;
int x = 0;
int product = x * y;
while (true)
{
product = x * y;
x++;
y++;
if (product == 24)
{
cout << x << " " << y << endl;
}
}
that is the code I tried doing it with but I realized that since x and y are increasing at the same time it will never reach 24 as a product.
Rather than
y++, tryy = 24 / x. Just startxat1, not zero!So: