fork download
  1. //Cecilia Rangel CSC5 Chapter 6, P.375, #21
  2. //
  3. /**************************************************************
  4.  *
  5.  * PRIME NUMBERS
  6.  * ____________________________________________________________
  7.  * This program will ask for the user to input a positive
  8.  * number, and the program determines if the number is a prime
  9.  * number
  10.  *
  11.  *_____________________________________________________________
  12.  * INPUT
  13.  * user input : a number to be evaluated
  14.  *
  15.  * OUTPUT
  16.  * prime : determining whether or not user input
  17.  * is a prime number
  18.  *
  19.  *
  20.  **************************************************************/
  21. #include <iostream>
  22. #include <cmath>
  23. #include <iomanip>
  24. using namespace std;
  25.  
  26. bool isPrime(int); //prime function
  27.  
  28. int main() {
  29. int number;
  30.  
  31.  
  32. cout << "Please enter a number and i will check if it is a prime."
  33. << endl;
  34. cin >> number;
  35.  
  36.  
  37. if (isPrime(number))
  38. {
  39. cout << number << " is a Prime number." << endl;
  40. }
  41. else
  42. cout << number << " is not a Prime number." << endl;
  43.  
  44. return 0;
  45. }
  46.  
  47. //**********************************************************
  48. // isPrime function definition. This function determines *
  49. // whether or not the integer entered by the user is a *
  50. // prime number or not. *
  51. //*********************************************************
  52. bool isPrime(int number)
  53. {
  54. for (int checker = 2; checker <= number; checker++)
  55. {
  56. if (number % checker == 0)
  57. {
  58. if(number == checker)
  59. return true;
  60. else
  61. return false;
  62. }
  63. }
  64. return false;
  65. }
Success #stdin #stdout 0s 5320KB
stdin
10
stdout
Please enter a number and i will check if it is a prime.
10 is not a Prime number.