Search:  

 
 
   All ForumsHot TopicsGallery






how-to block ads


 
Forums » Tech and Talk » OS and Software » Webmasters and Developers » please tell me why my c++ app doesnt work?
Search Topic:
Uniqs:
178
Share Topic:
RSS topic:
toggle:
flat / full
normal / watch
Posting:
Post a:
Post a:
Bad TCP checksum generated by LKM »
« [Javascript] Submit button not working.  
AuthorAll Replies


aleshik1

join:2004-07-10
Newark, NJ
·Optimum Online


1 edit
please tell me why my c++ app doesnt work?

#include
using namespace std;
int main(){


int number;
int factor;
int remainder;
int test;

for (number=4;;number++)

{
for (factor=2;factornumber;factor++)
{
int remainder=number/factor;
if (int remainder=0){int test=0;}
for(;test=0;number++){}

}

if(test!=0){cout number;}

}

return 0;
}

I want it to display prime numbers from 4 and above.By tweaking it I can either get it to display all numbers or none at all.I cant seem to get it right.


PToN

join:2001-10-04
Houston, TX

your for loops are all wrong. Check your book and re-read the looping chapter. Or make a google search so you can understand it.

It should look something like:


Steve
I'm a PC, so shut up
Consultant
join:2001-03-10
Yorba Linda, CA
reply to aleshik1
You'll also need to use the [code]
tags so we can see your code; many of us (including me) won't really even look at stuff that's essentially unformatted.


cowboyro

join:2000-10-11
Shelton, CT
reply to PToN
condition doens't always have to exist in his case since it's for all numbers - so basically an infinite loop


cowboyro

join:2000-10-11
Shelton, CT
·AT&T U-Verse
·Comcast
·Optimum Voice

reply to aleshik1
this shoud give a hint - haven't checked it though


cowboyro

join:2000-10-11
Shelton, CT
·AT&T U-Verse
·Comcast
·Optimum Voice

reply to aleshik1
Anyway this is the low level, brute force approach...
However it can be refined since:
-all even numbers greater than 2 are NOT prime as they can be divided by 2, so only odd numbers should be tested
-divisors that are even numbers should not be tested as they are multiple of 2, and you know the odd numbers that you are testing cannot be divided by 2 with a reminder of 0
Therefore you can tweak the code to start with number 3 for testing and increment by 2, and for divisor start with number 3 and increment by 2.


PToN

join:2001-10-04
Houston, TX

reply to cowboyro
quote:
from 4 and above

I missed the "above" part :) , even then he could still used a condition

But i see what you saying :p
-
Forums » Tech and Talk » OS and Software » Webmasters and DevelopersBad TCP checksum generated by LKM »
« [Javascript] Submit button not working.  


Tuesday, 24-Nov 11:54:07 Terms of Use | Privacy Policy | Hosting by www.nac.net - DSL,Hosting & Co-lo | feedback | contact
over 10 years online! © 1999-2009 dslreports.com.
page compression OFF
Most commented news this week
· [95] New AT&T Ad Campaign Hits Back At Verizon
· [67] New Bill Takes Aim At Higher Verizon ETFs
· [30] Earthlink Suffers From Major E-mail Outage
· [30] AT&T Offers New Prepaid Wireless plans
· [27] Frontier Increases Modem Rental Fee
· [15] Vivendi In Way Of Comcast's NBC Desires
· [13] Charter Still Fighting With Creditors
· [10] Senators Want ACTA Made Public
· [10] FCC 'Forgets' There's Limited Competition
· [7] Monday Morning Links
Most people now reading
· Windows 7 boot manager editing questions [Microsoft Help]
· hawaii in thanksgiving [General Questions]
· Big Bank Alternative to Bank of America? [General Questions]
· What to use while demonoid is down? [Filesharing Software]
· CTV & Canwest ask CRTC to order blocking of U.S. programs [TekSavvy]
· Slow speeds in the evenings [TekSavvy]
· Got a ticket [Canadian Chat]
· 3.x Feral Druid - Bear Tanking Guide [World of Warcraft]
· Killing the source - Google bans advertisers, not just ads [Security]