positive integer N program assistance

ok so i have to come up with something that will be prompt the user to input a positive integer N. the program should accomplish two tasks. For every natural number M that is less than or equal to N,
- Generate a list of all divisors of M, and
- Test to see if M is prime number.
Input: A positive integer (natural number) interactively.
what help do u ned?
Im kinda lost in knowing where i should start hahahha, im kinda of a novice programmer and am trying to teach this to myself
closed account (EzwRko23)
Hint: Sieve of Eratosthenes.
well this is what i have so far
but i dont know where to place the "cin>>" also im not sure why it wont run :(

#include <iostream>
using namespace std;

int isPrime(long num)
{
if (num < 2)
return 0;

if (num > 2 && (num % 2) == 0)
return 0;

for(int i = 2; i < num; i++ )
{
cout << " divisor: " << i << endl;
if ( (num % i) == 0)
{

return 0;
}
}


this is what the end program is sapose to look like
Input a positive integer : 8
Testing 1 ->
The divisors: 1
The number 1 is not a prime number.
Testing 2 ->
The divisors: 1 2
The number 2 is a prime number.
Testing 3 ->
The divisors: 1 3
The number 3 is a prime number.
Testing 4 ->
The divisors: 1 2 4
The number 4 is not a prime number.
Testing 5 ->
The divisors: 1 5
The number 5 is a prime number.
Testing 6 ->
The divisors: 1 2 3 6
The number 6 is not a prime number.
Testing 7 ->
The divisors: 1 7
The number 7 is a prime number.
Testing 8 ->
The divisors: 1 2 4 8
The number 8 is not a prime number.
do you have a main function?
put the cin at the main function and pass the user inputs into the isprime function.
If you read what your assignment is it has the clues you need to make it work.

Lets break it down:

-->>prompt the user to input a positive integer N
//The number "has" to check to be positive for it to be valid

-->>For every natural number M that is less than or equal to N,
Generate a list of all divisors of M.

// So, create a for loop

-->>Test to see if M is prime number //Guesing you meant N :)
//use the loop to check if it's a prime number


So, A function to check if the number is valid, And a function to check if it's a prime number

http://www.anyexample.com/programming/cplusplus/cplusplus_function_for_prime_number_check_(primality_test).xml

that should help you on your way.

Topic archived. No new replies allowed.