# Thread: Programming newbie seeking help!

1. ## Programming newbie seeking help!

I'm REALLY not good at programming. Sometimes its hard for people to fully explain how to do something. I'm supposed to write a program that prints the integers in the range of 1 to 100 that are evenly divisible by 3 but not evenly divisible by 6. I managed to create:

Code:
```#include <stdio.h>

int main(void)
{
int i;
int w = 0;

for (i=1; i<=100; i++)
{

if(i%3 == 0 && i%6 != 0)
printf("The numbers that are evenly divisible by 3 and not 6 are: %2d/3\n", i);

}

}```
The output repeats "The numbers '' '' '' for each found integer. How do I get it to only list it ONCE, and how do I get the program to keep count until the last found number?

And then I have to write a similar program that, beginning with the integer 1, finds the integers that are evenly divisible by 3 or 4 and/or evenly divisible by 5 or 6. The program is supposed to stop after its found 5 integers that are divisible by 5 or 6.

Can someone please explain to me, with examples, as to what I'm missing? And how I'm supposed to do it?

2. Originally Posted by jaja009
I'm REALLY not good at programming. Sometimes its hard for people to fully explain how to do something. I'm supposed to write a program that prints the integers in the range of 1 to 100 that are evenly divisible by 3 but not evenly divisible by 6. I managed to create:

Code:
```#include <stdio.h>

int main(void)
{
int i;
int w = 0;

for (i=1; i<=100; i++)
{

if(i%3 == 0 && i%6 != 0)
printf("The numbers that are evenly divisible by 3 and not 6 are: %2d/3\n", i);

}

}```
The output repeats "The numbers '' '' '' for each found integer. How do I get it to only list it ONCE, and how do I get the program to keep count until the last found number?

And then I have to write a similar program that, beginning with the integer 1, finds the integers that are evenly divisible by 3 or 4 and/or evenly divisible by 5 or 6. The program is supposed to stop after its found 5 integers that are divisible by 5 or 6.

Can someone please explain to me, with examples, as to what I'm missing? And how I'm supposed to do it?
You have the notice "The numbers that are evenly divisible...", inside the inner part of the loop. Why not move that printing to someplace just before the loop starts, and then it will print, just once?

You should not need to divide i by anything, at any time, in your program. You want to print the numbers that meet your specifications, and those numbers will always be the value of i.

If you want to count how many numbers you find that meet your criteria, then:

Code:
```int count;
. . .
count = 0;
if((i % 3 == 0) && (i % 6 != 0)) {
print i here;
count++;
}```
When you combine multiple logical statements, like here, it's a great idea to encapsulate each expression, into it's own parenthesis (), so the terms are evaluated as you'd expect, without relying on C's standard precedence table. That table can throw you some curves.

3. Hey THANKS A LOT!! I managed to get it! :
Code:
```#include <stdio.h>

int main(void)
{
int i;
int count = 1;

printf ("The numbers that are evenly divisible by 3 and not 6 are: \n");

for (i=1; i<=100; i++)

{

if(i%3 == 0 && i%6 != 0){
printf("%2d  . %2d\n", count, i);
count++;
}

}

}```
It works perfectly!! =D