Need help in oldschool C programming

Jimmah

Golden Member
Mar 18, 2005
1,243
2
0
I have an assignment, idea is to use 100 and increment it with 1, then check to see if it divides with 3 and 4, outputting if either do or do not divide evenly, stopping the program once a number is reached that both divide into.

Problem is, I'm clueless where to start. I understand I need to use 'for' then 'if', but I'm unsure how to word it (and wth is % exactly? the book doesn't touch on it much - or at all that I can find - so I'm very frustrated with it atm).

I can program increments, and silly stuff like that, just can't figure out for the life of me how to divide by two things and output the needed lines depending on if its true or false.


*not looking for the program written, just some pointers or a direction where to look*

Thanks for any help :)
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
The % operator is the modulo operator for C/C++/Java/C#. When referring to it we usually say "x mod y". The operation provides the remainder of a division, so 10 % 2 == 0, 10 % 5 == 0, 10 % 3 == 1, and 10 % 4 == 2.

So your algorithm can simply loop, incrementing the test value on each iteration, and if the result of x % 3 and x % 4 are both 0, do whatever you do on success. Here's a snip...

int test = 100;
while ( test % 3 != 0 || test % 4 != 0 )
test++;
printf( "%i", test );