Computing.Net > Forums > Programming > prime number algorithm

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

prime number algorithm

Reply to Message Icon

Name: tarheel4ever
Date: January 14, 2007 at 11:03:49 Pacific
OS: xp
CPU/Ram: p4
Product: dell
Comment:

Am i missing something here:

#include "primes.h" /*how to linkto main.c*/

int is_prime(int n)
{
int k;
int limit;

if (n == 2)
return 1;
if (n % 2 == 0)
return 0;
limit = n / 2;
for (k = 3; k <= limit; k += 2)
if (n % k == 0)
return 0;
return 1;
}
I do not think that this works. What I am trying tho do is prime number search up to a specific number input from keyboard. I have xphe, P4 3.0 512KMB, nvidia 6800. Using micro$oft visual 2005.

The first row is the amount of primes you want to see: printf("%5d: ", i);

How do I link is_prime() to main to display all prime numbers after the ":"

I have looked at C++ programming website and was unable to locate answer. I have found prime number algorithm but it didn't work on my machine. "By the way I'm a newbe @ programming. Any help would greatly be appreciated

Hmmmmmmmm........



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: prime number algorithm

Help! Test if a number is Prime in C++ www.computing.net/answers/programming/help-test-if-a-number-is-prime-in-c/2794.html

Find prime numbers in Java? www.computing.net/answers/programming/find-prime-numbers-in-java/11287.html

Prime number checking www.computing.net/answers/programming/prime-number-checking/6158.html