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 3 of 10 Topic 45760 of 47006
Post > Topic >>

Re: nested for loop problem

by red floyd <no.spam@[EMAIL PROTECTED] > May 5, 2008 at 11:50 AM

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).
 Be a 
bit more specific as to "this isn't working".  What are your inputs? 
What is your output?  What 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 ()
> {
> 	int a, b, c, d;
> 
> 	cout << "Enter two integers ";
> 		cin >> a >> b;
> 
> 	for (c=a; c==b; c++)
are you sure this is what you want?  The loop will only execute as long 
as the second statement is true.  So if a and b are different, well... 
nothing happens (which I assume is your complaint).
> 	{
> 		for(d=2; d<=sqrt(c); d++)
> 		{
> 			if(c%d==0)
> 				continue;
> 
> 			else cout << c;
> 		}
> 	}
> 	cout << " are the prime numbers in the range " << a << " to " << b <<
> endl;
> 
> 	return 0;
> }
 




 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:07:36 CDT 2008.