1. Find first 100 prime numbers 2. Read below

guys, I know it's been asked a lot about it here, but that's what I should do (though I'm not quite sure what the teacher wants, is n should be 100, 1000 and further, or use prime numbers. The "first draft" is due this Sunday, the "final draft" is due next week. I'm a complete noob in programming, but really do want to learn it. So, here's my homework (2 parts):

1. Write a program that computes and displays the first 100 prime numbers. Be sure to design your program to include a function (which you must write yourself) called isPrime() whose specification is a follows:

bool isPrime (long long n);
// Returns true if n is a prime, else false

2. Write program that examines the conjecture above as follows:

Write a loop that sets a variable n to 100, 1000, 10,000, 100,000, 1,000,000, 10,000,000 in turn. For each of the specified values of n, your program should compute the sum of the logarithms of all the primes from 2 to n, and display the sum of the logs of the primes, the number n, and the ratio of these two quantities computed to 5 decimal places.

The results should be displayed in a table with 6 rows (for each of the 6 values of n) and 3 columns the sum of the relevant logarithms, n, and the ratio). The correct results are given later in this document.

You should be able to make some changes to your solution to part 1 to solve part 2.

The correct output should look like this:

Sum of logs n Ratio
83.72839 100 0.83728
956.24527 1000 0.95625
9895.99138 10000 0.98960
99685.38927 100000 0.99685
998484.17503 1000000 0.99848
9995179.31786 10000000 0.99952
Press any key to quit:

My ideas:
My idea is that this code somehow will help me with the part 1. Not sure though. I need to give only e^n part, not the primary
 #include <iostream>

using namespace std;

void prime_num(int);

int main(){

cout << " Enter a number and I will generate the prime numbers up to that number: ";
int num = 0;
cin >> num;
prime_num(num);
}

void prime_num( int num){

bool isPrime=true;

for ( int i = 0; i <= num; i++) {

for ( int j = 2; j <= num; j++){
if ( i!=j && i % j == 0 ){

isPrime=false;
break;
}
}

if (isPrime){

cout <<"Prime:"<< i << endl;
}
isPrime=true;
}
return 0;
}

Program to output all prime numbers between 3 and 100

The program is suppose to output all the prime numbers between 3 and 100.It acutally outputs all numbers between 3 and 100.My code is as follows:#include <iostream>using namespace std;int main (){int number=3, count=2;while (number <= 100){if ((number % count) > 0){cout << number ...

Prime numbers from 1 to 100

Please, I need help in this little problem of printing all the prime numbers from to 100. Please, if you have more than one method to the question, I would really appreciate it. I also need it as soon as possible. ...

Write a program that displays all the prime numbers between 50 and 100.

Write a program that displays all the prime numbers between 50 and 100.Below is my code:Write a program that displays all the prime numbers between 50 and 100.please correct my mistake, thank you.#include <stdafx.h>#include "genlib.h"#include "simpio.h"#include "math.h ...

Write a program to display all the pairs of twin prime numbers that are less than 100

A pair of (positive) integer numbers are called twin primes if they are both prime numbers and the difference between them is 2, i.e. they are consecutive odd numbers and they are prime numbers. (3, 5), (5, 7) and (11, 13) are three examples of such pair of twin prime numbers. Write a program to dis ...

Help with printing prime numbers 1-100

I have the following code attached that gives me a prime number. I can't seem to put the logic behind having this code print from an alert the prime numbers from 1-100. Of course, this code is only giving me "the" prime number. I just don't know where to begin, or how to store each number. ...

Find Prime Numbers - Need Assistance

I would like to create a script that allows for a user to input two integers and to have the script show all the prime numbers that fall between them.Any thoughts? ...

Finding Prime Numbers with Sieve of Eratosthenes(C++)

I'm trying to do an exercise to find prime numbers using The Sieve of Eratosthenes in C++. I have been working at this for hours and can't get it to work right, so maybe someone can help? I don't know if I'm close or totally off. There's some extra code I put in here to kinda debug things by printin ...

C++ prime numbers query

i am trying to make a C++ prog. When i enter a number it will test if the number is a prime numberif it is it will display Prime... if not it will display not prime...pretty simpleso far:#include <iostream>#include <cstdlib>using namespace std;int main (){int number; //user inputed numbe ...

Prime numbers (plain DB2)

In mathematics, a prime number (or a prime) is a natural number which has exactly two distinct natural number divisors: 1 and itself. The first twenty-five prime numbers are:2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97....To find prime numbers we'll ...

Prime Numbers

I'm making a program when the person types an EVEN number greater than two it adds two prime numbers that equal that number.so if you enter 480it says " Two primes that add up to 480 are 13 and 467 " but it adds one prime number and another non prime. try my code and type in 150 here is a ...

Prime numbers and adding

I can't seem to get it to add cout << "\nEnter the number of terms - ";cin >> n;ctr = 0; //counter variablefor(num = 2; ctr < n; num++){flag = 1;for(i = 2; i <= num/2; i++){if(num % i == 0)flag = 0;break;}if(flag == 1)cout << num << "\t";sum += num;c ...

how can I find out the prime numbers in given integers in PHP?

how can I find out the prime numbers in given integers in PHP? ...

Prime numbers in plain DB2

In mathematics, a prime number (or a prime) is a natural number which has exactly two distinct natural number divisors: 1 and itself. The first twenty-five prime numbers are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97.... You have to know: Doesn't ...

help with array that determines prime numbers

My assignment for class was to produce a program that runs the seive of eratosthenes to determine all the prime numbers between 2 and n, with n no larger than 100. I tryed to write the program with a boolian array that will turn all non-primes to false up to the max of 100, and then only output to t ...

prime numbers homework trouble

i have to define a function that tests number from 2 to 10000 to see if they are prime. heres what i have so far. #include <iostream>#include <iomanip>using namespace std;bool find_prime(int);int main (){int i, counter =0;bool test;for (i =2; i <= 500; i++){test = find_prime(i);if ( t ...

Prime Numbers

:cry: i'm so confused right now,can any one help with this?defining a functoinbool prime (int n)which prints 10000 prime numbers ...

(Noob) need some help w/ Prime Numbers

I know there are tons of posts on this, I think I'm on the right track with this, but I can't quite get it to work. I can't figure out how to get the range of primes to print. I'd appreciate any input I can get, sorry about the indenting. main() keeps doing the following, until user enters a 0 or a ...

Finding prime numbers in Javascript (Sieve of Eratosthenes)

I don't know what it is, but I canNOT grasp this one."Create an array with all elements initialized to 1 (true)."I did this successfully and have 100 1's across my document.var sieve = new Array(100);for (var i=0; i < sieve.length; i++) {sieve[i] = 1}document.write("<td> ...

Prime Numbers - Help its for college

Ok i need the user to be asked for a number by an inputbox (Using VB 6) and have this number checked. If its prime i want them to be told via msgnox , if not i want them to be given another attemptAny ideas? ...

Print out Prime Numbers

I just had to do this to see how it would look like in the code field. This small prime number generator is written in BCX basic, a mildy more modern basic than Qbasic. With BCX basic you can throw in C and assembler code and it would actually compile it. Gives you the familiar comfort of basic, but ...

C++ Finding Prime Numbers

again I need a little help with this assignment. What I'm supposed to do is have a user enter a positive integer and then the program should tell the user all the prime numbers before the number the user entered. However, with my program when I enter 22 for example it will give me numbers like 25, 2 ...

how do u find prime numbers in an array

hlp please ...

Prime Numbers

Here I made a GUI template with a Form, Button and Listbox using MS VCS 2003. MS VCS 2003 still produces a single file usable as a templet, whereas MS VCS 2005 smears files all over the map. Must be some marketing persons idea of market dominance.I took the source file, removed all the usual gibberi ...

Help with prime numbers

:rolleyes: I need some one to define prime numbers for meA full definition, I am trying to write a program to determine wether a number is prime, print all prime numbers in a specific range ... e.t.c so i need a full definition of prime numbers, i know prime numbers are divisible only by one and the ...

Help with prime numbers

Please i need help with prime numbers... i have been cracking my brain for the problem since two days ago..... I used this test code but there is a problem with it for( number=3; number<=1000; count++){//to test number 3 to 1000if(number%2 != 0){//to skip even numbersfor(int count=2; count<=nu ...

Finding Prime numbers without using Boolean

Here is a program which finds prime numbers, but because the compiler i need to use for my class does not use a boolean variable i am having trouble figuring this out. Please help me find how to find prime numbers without using a boolean variable.#include <iostream>using namespace std;void pri ...

help with prime numbers!

including the 2 conditions that r chekd for prime numberS ...

Code to generate first 10 prime numbers

Friends, Can any one help me in writing code to(a) Generate first 10 prime numbers, (b) Find highest common factor(hcf) of 3 numbers, and (c) Program to print the first N number in the fibonacii series.I am a beginner. I need help and guidance to become a good and efficient programmer, pl.incidental ...

Program that finds prime numbers

So after a day or two of trying i finally found out how to do this, my question is, is there any way to do this that is more efficient without using the prime function?#include <iostream>using namespace std;int main(){std::string line;int i, p, x;for(i = 3; i <=100; i++) {for(p=2; p<i; p ...