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:
225
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.  


Sunday, 06-Dec 07:45:24 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
· [163] Comcast Releasing Promised Usage Meter
· [147] Avast Antivirus Has Gone Mad
· [128] Comcast Makes NBC Universal Acquisition Official
· [125] The Bandwidth Hog Does Not Exist
· [105] Graduate Student Unveils Sprint's GPS Sharing With Feds
· [101] Google Invades ISP, OpenDNS Turf With Google Public DNS
· [85] FCC Ponders Moving From PSTN To IP Voice
· [82] Latest Consumer Reports Survey Not Kind To AT&T
· [81] New Bill Aims To Limit ETFs
· [75] Sprint Defuses GPS Privacy Media Bomb
Most people now reading
· Wife might have to work in.... Iowa for a few months!!! [General Questions]
· [DNS] Google's public DNS... performance increases? [Comcast HSI]
· [ Classes] 3.2.2 Rogue [World of Warcraft]
· Is there any true cure for, or way to prevent, a hangover? [General Questions]
· Windows 7 boot manager editing questions [Microsoft Help]
· Google takes aim at browser redirection [Security]
· False positive in Avast! or is it real? [Security]
· Bulb for garage door opener [Home Repair & Improvement]
· Maximizing Rogue DPS for 3.1 [World of Warcraft]
· First commercial tool to crack BitLocker arrives (Updated) [Security]