Menu
Menu
DaniWeb
Log In
Sign Up
Read
Contribute
Meet
Search
Search
About 1,000 results for
isprime
- Page 1
Re: isPrime()
Programming
Software Development
17 Years Ago
by Narue
… it hard to believe that you can write
IsPrime
but not the main driver to print the… [0..100). I'm guessing you were given
IsPrime
and told to write main, which means [B… is loop from 0 to 100 and call
IsPrime
on the current number. If it returns true…( int i = 0; i < 100; i++ ) { if (
IsPrime
( i ) ) cout<< i <<" is prime…
Re: isPrime()
Programming
Software Development
17 Years Ago
by JRM
… I find it hard to believe that you can write
IsPrime
but not the main driver to print the primes in… the range [0..100). I'm guessing you were given
IsPrime
and told to write main, which means ***you've*** come…
Re: isPrime()
Programming
Software Development
14 Years Ago
by hvengel
An even more efficient and generalized
isPrime
() function. [CODE]bool
isPrime
(unsigned int number) { if (number > 3) { if (number % 2 == …
Re: isPrime()
Programming
Software Development
14 Years Ago
by hvengel
…} sieveValue++; } sieve.push_back(wheelFactor + 1); sieveFull = true; } bool
isPrime
(unsigned int candidatePrime) { if (!sieveFull) fillSieve(); int fp = 0; while…; } [/CODE] Here is a wheel factorization version of
isPrime
. This uses a small wheel factoring sieve based on the…
isPrime()
Programming
Software Development
17 Years Ago
by forumposters
I need to write a main() function, that loops over a bunch of numbers from 0 to 100, calls another function called
isPrime
() for each of them, and print out the numbers that are prime. I'm new to C++ and any help would be appreciated.
Re: isPrime()
Programming
Software Development
17 Years Ago
by sillyboy
What narue said applies. But I'll help you a little:
isPrime
(int x)
Re: isPrime()
Programming
Software Development
17 Years Ago
by forumposters
Here's what I've come up with so far: [code] #include <iostream> bool
IsPrime
(int num) { if(num == 0) return true; num = abs(num); for(int i = 2; i <= sqrt(num); i++) if(num % i == 0) return false; return true; }[/code]
Re: isPrime()
Programming
Software Development
14 Years Ago
by soeja
This is more efficient. #include <iostream> bool
IsPrime
(int num) { if(num == 0) return true; num = abs(num); if(num % 2 == 0) return true; for(int i = 3; i <= sqrt(num); i+=2) if(num % i == 0) return false; return true; }
Re: isPrime()
Programming
Software Development
14 Years Ago
by soeja
[CODE]#include <iostream> bool
IsPrime
(int num) { if(num == 0) return true; num = abs(num); if(num % 2 == 0) return true; for(int i = 3; i <= sqrt(num); i+=2) if(num % i == 0) return false; return true; }[/CODE]
Re: isPrime()
Programming
Software Development
14 Years Ago
by parameshyss
Hi Soeja, This is more efficient.. and for 4 , 6 , 8(i.e., even no) .. ur code snippet will give wrong ans.. [code=c] #include <iostream> bool
IsPrime
(int num) { if ( 2 == num ) return true ; int l = sqrt(num) ; for(int i = 3; i <= l; i+=2) if ( 0 == ( num % i ) ) return false; return true; } [/code]
Re: IsPrime.cpp
Programming
Software Development
15 Years Ago
by csurfer
… Hiroshe): [B]1>[/B] [QUOTE]if (
IsPrime
(num)==(true))[B][COLOR="Red"];[/COLOR][/B]… don't do redundant work as in [B]
IsPrime
(num)==(true)[/B] the following is enough: […code=c] if (
IsPrime
(num)) //No semicolon and a return of 1… [/code] [B]2>[/B] And in your
IsPrime
function with this line : [code=c]for (i=3…
IsPrime.cpp
Programming
Software Development
15 Years Ago
by ndfi54
…quot;random.h" #include <math.h> bool
IsPrime
(int num); int main() { int num; num=2; printf(&…num); for (num=3;num<=100;num+=2) { if (
IsPrime
(num)==(true)); { printf("%d\n", num); } } } …bool
IsPrime
(int num) { int i; double limit; if (num<=1…
Re: isPrime()
Programming
Software Development
17 Years Ago
by Narue
>I'm new to C++ and any help would be appreciated. At least start trying to solve your problem before asking for help. It makes us like you more and ignore you less.
Re: isPrime()
Programming
Software Development
17 Years Ago
by WaltP
You've been around over a year and haven't read [url=http://www.daniweb.com/techtalkforums/faq.php?faq=daniweb_policies]the Rules[/url] yet? You also need to [url=http://www.daniweb.com/techtalkforums/thread78223.html]read this[/url]. It will explain that you need to tell us what problem you are having so we don't have to guess -- among other …
Re: isPrime()
Programming
Software Development
14 Years Ago
by parameshyss
Gud work hvengel.. :)
Re: isPrime()
Programming
Software Development
14 Years Ago
by StuXYZ
I am surprised reading this, I would have thought most of you knew the +2,+4 rule -- but it hasn't come up, just the old +2 rule. Assuming that you are not going to use the memory that the typical sieve methods use, or the complexity of the more you can extend the idea that you increment the test by +2 to +2,+4 as below. [code=C++] bool …
Re: isPrime()
Programming
Software Development
14 Years Ago
by pseudorandom21
I think a sieve that uses a bit of memory is way better than using that much CPU time, you can generate millions of primes in a few seconds using a sieve.
Re: isPrime()
Programming
Software Development
14 Years Ago
by pseudorandom21
[url]http://en.wikipedia.org/wiki/Primality_test[/url] You might also look into the sieve of eratosthenes, and other algorithms for generating primes. [url]http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes[/url] There are links to other algorithms at the bottom, such as the sieve of sundaram, etc.
Re: isPrime()
Programming
Software Development
14 Years Ago
by yashsaxena
prime number program :) Still remember the initial days of C & CPP programming Language. :P :)
Re: isprime function (Python)
Programming
Software Development
10 Years Ago
by TrustyTony
Interesting HiHe, but I do not know if it is too biased to use only one number as case. Both isprime2 and
isprime
3 seem to run more than my own
isprime
adapted as optimized from Project Euler (found in other prime tread recently posted to) Tony
Re: isprime function (Python)
Programming
Software Development
10 Years Ago
by HiHe
… little timing experiment: ''' timeit_isprime.py check the speed of three
isprime
functions ''' import timeit import sys print(sys.version) def isprime2…
C4715: 'isPrime' : not all control paths return a value
Programming
Software Development
17 Years Ago
by Yaka
…running how ever it gives this warning....C4715: '
isPrime
' : not all control paths return a value....i…; "is a prime number\n"; } if (
isPrime
(number)==false) { cout << "\n"…Invalid number entered\n"); exit(1); } } int
isPrime
(int number) { int count=0,count1; for(count1=2;…
Re: C4715: 'isPrime' : not all control paths return a value
Programming
Software Development
17 Years Ago
by Yaka
… the warning off. and yea i made the int
isprime
,,, a bool
isprime
. thanks. but still i dont know how to fix…
Re: Help creating an isPrime function
Programming
Software Development
13 Years Ago
by mrnutty
…[code] #include <iostream> using namespace std; bool
isPrime
(int number){ bool isPrimeNumber = false; //do logic here return …lt;< "Is 97 prime: " <<
isPrime
(97) << endl; //should be true cout <<… << "Is 27 prime: " <<
isPrime
(27) << endl; //should be false return 0; } …
Re: Help creating an isPrime function
Programming
Software Development
13 Years Ago
by mrnutty
…[code] #include <iostream> using namespace std; bool
isPrime
(int number){ bool isPrimeNumber = false; //do logic here return …lt;< "Is 97 prime: " <<
isPrime
(97) << endl; //should be true cout <<… << "Is 27 prime: " <<
isPrime
(27) << endl; //should be false return 0; } …
Recursive isPrime function in python
Programming
Software Development
11 Years Ago
by birinci2012
def
isPrime
(num,div=2): if(num==div): return True elif(num % div == 0): return False else: return
isPrime
(num,div+1)
Re: Help creating an isPrime function
Programming
Software Development
13 Years Ago
by rigoalhn
…;iostream> #include <iomanip> using namespace std; bool
isPrime
(int number){ int remainder; bool isPrimeNumber = false; cout<<…; boolalpha << "Is 5 prime : " <<
isPrime
(number) << endl; system("pause"); return 0…
Re: Recursive isPrime function in python
Programming
Software Development
11 Years Ago
by Gribouillis
Probably the worst `
isPrime
()` function I've ever seen. If num is above 1000000, …
Help creating an isPrime function
Programming
Software Development
13 Years Ago
by rigoalhn
… helped me. I need a write a boolean function named
IsPrime
that takes and integer as argument and returns true if…
Timing five isprime functions (Python)
Programming
Software Development
10 Years Ago
by vegaseat
Just trying to find out which of these five
isprime
functions is the fastest.
1
2
3
17
Next
Last
Search
Search
Forums
Forum Index
Hardware/Software
Recommended Topics
Programming
Recommended Topics
Digital Media
Recommended Topics
Community Center
Recommended Topics
Latest Content
Newest Topics
Latest Topics
Latest Posts
Latest Comments
Top Tags
Topics Feed
Social
Top Members
Meet People
Community Functions
DaniWeb Premium
Newsletter Archive
Markdown Syntax
Community Rules
Developer APIs
Connect API
Forum API Docs
Tools
Backlink Auditor
Legal
Terms of Service
Privacy Policy
FAQ
About Us
Advertise
Contact Us
© 2025 DaniWeb® LLC