I'm in serious need of help with a C++ based prime number generator. I have the program to create and run the code, but i dont have the knowledge to develop the code and I'm looking for one of you guys to build the code for me.

I need a prime number algorithm developed for C++

I have VERY specific guidelines as to the process in which the program calculates the result, all of which should make the program easier to run.

(conditions)
number being checked must not end in 2,4,5,6,8, or 0(reduces the amount of numbers needing checked by alot. valid statement by the fact that any number ending in 0, 2, 4, 5, 6, or 8 is automatically divisible and therefore, not prime.)

number must have no factors other than itself and 1(just to ensure the specification and definition of what a prime number is)

1 is not prime


if number does not end in 2,4,5,6,8, or 0 then the number need not be divided by 2, or 5 (reduces the number of factors needing checked by alot)


number being checked must be divided by 2,3,7, and any prime number less than the number being checked.(greatly reduces number of factors to check)

if, when divided, the number yields any whole value other than itself or 1, the number is not prime.
if, when divided by any factor less than itself, the number does not yield any whole value other than itself or 1 , the number is prime.

start with a number,
divide it by all numbers less than itself that fall within the division criterion,
check the results,
A) whole number on any result
B) decimal in all results

A) move to next number to be checked
B) set number into prime category for use in further calculations.


I understand that it might be hard to get things that specific into the programming, but any and all help would be greatly appreciated.

One suggestion would be to build a html parsing program and then perhaps connect to http://primes.utm.edu/lists/small/10000.txt and read out the list of primes into the memory and write them down to a file.
Or you could choose this website but the you'll need HTTP/POST feature to get the prime.

PS: I was joking on your laziness above. You won't get any ready made cookies here. Only if you had read the Forum Rules and Announcement you would have found that we only help those who show efforts.
So, Best of Luck!!!
My advices:
1.Learn C++
2.Learn some prime number generating algorithm; there seems to be many and most of them find Sieve of Eratosthenes to be quite effective
3.Try to implement it in C++. If you get struck, get back here with the code you tried on.

Ah, I had wondered if that wasnt the reply I was going to get.

Well, while your reply is entirely understandable, I do believe I stated in my opening post that I wanted someone else to do it. Commissioning isnt allowed here?

And I have already began trying to develop a base code to build from, but I dont have my book with me that contains all of the information I would need and it could be another 6 months before I have access to it.

on the topic at hand, I can 'generate' small prime numbers without any true algorithm, but studying prime numbers in the higher realm of numbers is not something I can easily do without the right tools, hence me coming here. I'm not a computer tech or programmer, I'm a mathematician of sorts. The fact that I took the time to give a very specific set of conditions shows that I have put effort into this idea. But as the old addage goes, if you want it done, you must do it yourself.

I can give you a code in c but not much effectful.

#include<stdio.h>
#include<math.h>

int main()
{
          long n,i,y=0;
          scanf("%ld",&n);
          for(i=2;i<=sqrt(n);i++)
                   if(n%i==0) 
                   {
                         y++;
                         break;
                   }
          if(y==0) printf("The number is PRIME");
          else printf("The number is not PRIME");
          return 0;
}
commented: Read the forum rules before making your next post. -4

let me start you off. This snippet generates prime up to 100. Fill in the
conditions. Its in java...hehe. So you need to understand the logic and convert it. Then you can fill in the needed requirements.

package helloworld;
 

public class Main
{
    static boolean isPrime(int num)
    {
        if(num < 2) return false;

        if(num == 2)
            return true;

        for(int i = 2; i < num; i++)
        {
            if(num % i == 0)
                return false;

        }

        return true;
    }
    public static void main(String[] args)
    {

        for(int i = 0; i < 100; i++ )
            if(isPrime(i))
                System.out.print(i + " is a prime\n");

    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.