# Simple for loop question

• 02-28-2011
benrogers
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:
Code:

```#include <stdio.h> int main() {     int a, b;         printf("Enter in an integer:\n");     scanf("%d", &a);         for (a = 1; a < 1000;  b = a + a)             printf("Your numbers are: %d.\n", b);         return 0; }```
It seems to just be running an infinate loop.

Any help would be greatly appreciated.
• 02-28-2011
anduril462
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:
Code:

`for (b = ?; b < 1000; b += ? )`
Now, what value does b start at in your example? Where did that come from? How much does b increment by each time?
• 02-28-2011
benrogers
Quote:

Originally Posted by anduril462
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:
Code:

`for (b = ?; b < 1000; b += ? )`
Now, what value does b start at in your example? Where did that come from? How much does b increment by each time?

Thanks for the help

Code:

`for (b = a; b < 1000;  b += a)`
Works like a charm!!