Advertisement
JamesDamico

BCS 120 - Assignment 4

Nov 13th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. //Assignment 4
  2. void assignment4()
  3. {
  4. char cont;
  5.  
  6. do
  7. {
  8. int number;
  9. bool isPrime = true;
  10.  
  11. cout << "Enter a positive integer: ";
  12. cin >> number;
  13.  
  14. for (int i = 2; i <= number / 2; ++i)
  15. {
  16. if (number % i == 0)
  17. {
  18. isPrime = false;
  19. break;
  20. }
  21. }
  22. if (isPrime)
  23. cout << "This is a prime number \n";
  24. else
  25. cout << "This is not a prime number \n";
  26.  
  27. cout << "Would you like to continue? Y/N \n";
  28. cin >> cont;
  29.  
  30. } while (cont == 'y' || cont == 'Y');
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement