Simple for loop question
I need to create a program using a for loop that will read in an integer, and print all the multiples of that integer up to 1000. e.g. given 7, will print 7, 14, 21, 28...(until the end)
This is what I have:
It seems to just be running an infinate loop.
int a, b;
printf("Enter in an integer:\n");
for (a = 1; a < 1000; b = a + a)
printf("Your numbers are: %d.\n", b);
Any help would be greatly appreciated.
Look at your for loop. You initialize a to 1, tell it to stop once a is greater than or equal to 1000 and increment b. Your loop variable should be b:
Now, what value does b start at in your example? Where did that come from? How much does b increment by each time?
for (b = ?; b < 1000; b += ? )
Thanks for the help
Originally Posted by anduril462
Works like a charm!!
for (b = a; b < 1000; b += a)