Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: nested for ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 10 Topic 45760 of 47006
Post > Topic >>

Re: nested for loop problem

by notahipee <werldpeace@[EMAIL PROTECTED] > May 5, 2008 at 11:56 AM

On May 5, 11:50=A0am, red floyd <no.s...@[EMAIL PROTECTED]
> wrote:
> notahipee wrote:
> > Would someone be able to tell me why this isn't working. The nested
>
> Please read the FAQ 5.8
> (http://www.para****ft.com/c++-faq-lite/how-to-post.html#faq-5.8).
=A0Be
a
> bit more specific as to "this isn't working". =A0What are your inputs?
> What is your output? =A0What is your *expected* output?
>
> Note that from a cursory examination of the code, I could figure out
> what "isn't working" means, but still...
>
> > for loops seem correctly coded to me. I would appreciate any input.
>
> > #include <iostream.h>
> > #include <math.h>
>
> > int main ()
> > {
> > =A0 =A0int a, b, c, d;
>
> > =A0 =A0cout << "Enter two integers ";
> > =A0 =A0 =A0 =A0 =A0 =A0cin >> a >> b;
>
> > =A0 =A0for (c=3Da; c=3D=3Db; c++)
>
> are you sure this is what you want? =A0The loop will only execute as
long
> as the second statement is true. =A0So if a and b are different, well...
> nothing happens (which I assume is your complaint).
>
>
>
> > =A0 =A0{
> > =A0 =A0 =A0 =A0 =A0 =A0for(d=3D2; d<=3Dsqrt(c); d++)
> > =A0 =A0 =A0 =A0 =A0 =A0{
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if(c%d=3D=3D0)
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue;
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else cout << c;
> > =A0 =A0 =A0 =A0 =A0 =A0}
> > =A0 =A0}
> > =A0 =A0cout << " are the prime numbers in the range " << a << " to "
<< =
b <<
> > endl;
>
> > =A0 =A0return 0;
> > }- Hide quoted text -
>
> - Show quoted text -

I am trying to get the first loop to cycle from integer a to integer
b.
The second loop is supposed to test each integer for prime. The output
I intend is to print out only the primes. My opening cout and closing
cout work but the loops produced nothing.
 




 10 Posts in Topic:
nested for loop problem
notahipee <werldpeace@  2008-05-05 11:42:26 
Re: nested for loop problem
"Victor Bazarov"  2008-05-05 14:47:15 
Re: nested for loop problem
red floyd <no.spam@[EM  2008-05-05 11:50:30 
Re: nested for loop problem
Christopher <cpisz@[EM  2008-05-05 11:53:08 
Re: nested for loop problem
notahipee <werldpeace@  2008-05-05 11:56:57 
Re: nested for loop problem
notahipee <werldpeace@  2008-05-05 12:01:05 
Re: nested for loop problem
notahipee <werldpeace@  2008-05-05 12:05:13 
Re: nested for loop problem
notahipee <werldpeace@  2008-05-05 12:17:40 
Re: nested for loop problem
Puppet_Sock <puppet_so  2008-05-05 13:25:56 
Re: nested for loop problem
MiB <Michael.Boehnisch  2008-05-06 09:12:50 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 2:12:58 CDT 2008.