Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Assignment 4
- void assignment4()
- {
- char cont;
- do
- {
- int number;
- bool isPrime = true;
- cout << "Enter a positive integer: ";
- cin >> number;
- for (int i = 2; i <= number / 2; ++i)
- {
- if (number % i == 0)
- {
- isPrime = false;
- break;
- }
- }
- if (isPrime)
- cout << "This is a prime number \n";
- else
- cout << "This is not a prime number \n";
- cout << "Would you like to continue? Y/N \n";
- cin >> cont;
- } while (cont == 'y' || cont == 'Y');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement