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.
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.