thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
Avoid that code above. First of all it doesn't work at all, aside from that, main has no return type, and has no return value either, and that's bad, very bad. Using system("pause") is also not recommended, use cin.get() instead.
if ((k%2!=0)&&(k%3!=0)&&(k%5!=0)&&(k%7!=0))
This statement only checks if a number can be divided by 2, 3, 5, 7. I can easily make up numbers that are not primes yet cannot be divided by 2 3 5 7. In fact any multiplication of prime numbers above 7 will be missed. Starting from 11, the wider the range the more you miss.
11 * 11 = 121
11 * 13 = 143
11 * 17 = 187
13 * 17 = 221
17 * 17 = 289
23 * 11 = 253
23 * 17 = 391
23 * 23 = 529
29 * 11 = 319
29 * 13 = 377
29 * 17 = 493
As thines01 indicated there are probably hundreds of threads about finding prime numbers already, try to do some search. I am sure you will find something useful.
LRRR
Junior Poster in Training
55 posts since Dec 2011
Reputation Points: 22
Solved Threads: 15
Skill Endorsements: 0
who told you that 121 is a prime number oh please
besides the code i have written works perfectly fine and i have tested it a hundred times
Please be reminded that the code you post should always be compatible with different (if not all) compilers
for example main should have a return type ..int to be exact
i can pretty easily guess that you are a noob at c++ as this code is made for dev c++ compiler which is popular nowadays
Keep it pleasant, don't be rude to other members, also I can say that he knows what he's talking about and is quite knowledgeable at c++ as i have seen his previous posts
zeroliken
Nearly a Posting Virtuoso
1,346 posts since Nov 2011
Reputation Points: 214
Solved Threads: 205
Skill Endorsements: 13
So what you need is more like prime factorization. There are many threads on this site that talk about that.
NathanOliver
Posting Virtuoso
1,513 posts since Apr 2009
Reputation Points: 269
Solved Threads: 277
Skill Endorsements: 3
who told you that 121 is a prime number oh please
If it did anything useful, your program would...
besides the code i have written works perfectly fine and i have tested it a hundred times
Really? I entered 130 and it output 32. How is that useful?
I added a cout to display the prime numbers it calculates and got
Enter thenumber till the check should go200
11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89
97 101 103 107 109 113 [B]121[/B] 127 131 137 139 [B]143[/B] 149 151 157 163
167 [B]169[/B] 173 179 181 [B]187[/B] 191 193 197 199
50Press any key to continue . . .
Where's 2, 3, 5, and 7? What is 121, 143, 169, and 187 doing in the list? And what the heck is 50????
It runs fine, but the answers are completely wrong... Therefore it's useless.
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 36
>>in the interval [x,y] how many numbers have exactly 14 divisors
24 has 16 integer divisors: 24, 1, 12, 2, 8, 3, 6, 4 (and respective negative ints)
24 has 8 positive integer divisors
24 has 2 prime divisors: 2 and 3, assuming the definition of prime divisors is divisors that are prime (and if you accept the definition that 1 isn't a prime number).
I know of no short cut way to determine the number of postive integer divisors a number has, except to say if the number is prime, then the number of divisors is 2. Maybe someone is aware of a nifty algorhithm to determine the number of positive integer divisors any given positive integer has. I'd use brute force.
Lerner
Nearly a Posting Maven
2,406 posts since Jul 2005
Reputation Points: 739
Solved Threads: 405
Skill Endorsements: 8