Yes, indeed. I didn't even comprehend his post, I was so indignantly "fixing" broli86's solution.
Yes, indeed. I didn't even comprehend his post, I was so indignantly "fixing" broli86's solution.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
I am now confused :S
Take a look at Salem's point of information:I am now confused
Use this idea to display all the numbers divisible by 6 in the range of 1 to 40.If x is a number which is divisible by 6, then doing x = x + 6 also results in a number divisible by 6.
When you are done, tackle the rows of 3 problem. If you still cannot solve that part, then come back here with your solution for the first part and we'll give you suggestions on how to solve the second part.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thank You!
Code:#include <stdio.h> int main(void) { int x,j=0; for (x = 1; x <= 40; x++) { if (j < 3) { if (x % 3 == 0) { printf("\t%i\t", x); j++; } } else { if ( j == 3) { j = 0; printf("\n"); } } } return (0); }
it works perfectly well..but,what if i need the user to enter the upper limit and the lower limit how can I do this witha do while loop....or a for loop..is it hard?? I mean instead of 1 to 40 it would be the user's chouice!!
Any suggestions???
thanks in advance guys!!
Not too difficult. Read the input from the user into variables and substitute the variables for the numbers.it works perfectly well..but,what if i need the user to enter the upper limit and the lower limit how can I do this witha do while loop....or a for loop..is it hard?? I mean instead of 1 to 40 it would be the user's chouice!!
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Emmm..That what I have done..I am onkly confused in the for loop condition..
OI dunno what to r write between ()
for(???????????)
If you go through with this plan, one isn't divisible by six, so it would be a bad idea to start there. It's a bad idea to start there anyway, but you'll be off by one for the duration of the program.If x is a number which is divisible by 6, then doing x = x + 6 also results in a number divisible by 6.
>> I am onkly confused in the for loop condition.
Don't be confused, just make an effort. You'll be counting (possibly by six) starting from lowerbound to upperbound.
emm..Makes sense but,still doesn't put me on the way
thanks for trying anyways
Why not start at 6? That is, by definition, the lowest number divisible by 6.
[edit] I'm telling you, that code that broli86 had is no good! If I change the condition if(x % 3 == 0) to if(1) -- presumably printing every number -- this is the output I get:
In other words, the loop is completely ignoring every fourth number. It's skipping them over and not even considering them. If one of those numbers happened to be divisible by 6, it wouldn't be printed.Code:1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31 33 34 35 37 38 39
What's so bad about my code? This
is the same as this, BTW.Code:if(++count % 3 == 0) putchar('\n');
Even better, what's so hard about Salem's suggestion? . . . . [/edit]Code:count ++; if(count % 3 == 0) { printf("\n"); }
[edit=2] Hint:
[/edit]Code:for(...; ...; x += 6)
Last edited by dwks; 07-05-2008 at 04:09 PM.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Thanks!! its not too hard..but,I am still a beginner