1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include<iostream>
#include<string>
using namespace std;
bool primeCheck(bool prime,int number, int &a, int &b)
{
for(int a=2;a<=number;a++)
{
for(int b=2;b<a;b++)
{
if(a%b == 0)
{
prime = false; // we found a value that can evenly divide into the number entered
break; //stops the loop
}
}
if(prime == true)
cout << "Prime number: " << a << endl;
else
prime = true; //reset prome back to true so we can continue to look for prime numbers
}
return true;
}
int getNumber()
{
int number;
cout << "Enter a number: ";
cin >> number;
return number;
}
int input(int counter,int number, int a)
{
cout << "Enter a number: ";
number[counter];
counter++;
return counter;
}
int main()
{
/*
write a program which will prompt the user for a number. then determine if that number is prime or not prime
a prime number is a just a number, nut it can only be evenly divisable by itself and the number 1
modulus is the math symbol we use to determine if one number can evenly divide into another
modulus % returns the remainder form a division operation
*/
int number;
int a,b;
bool prime = true;
int counter=0;
//bool variable holds true or false nothing else
number = getNumber();
prime = primeCheck(prime,number,a,b);
counter = input(counter, number);
system("pause");
return 0;
}
/*
for the assignment i asked you all to modify the above program so that it will list all prime numbers
from 2 to the number entered in by the user
25
2,3,5,7,11,13,17,19,23
7
2,3,5,7
*/
|