prac_005.cpp (613B)
1 /* check prime or not */ 2 3 #include <iostream> 4 using namespace std; 5 6 class ponp { 7 int input, i; 8 9 public: 10 void getinput(); 11 void calcdisp(); 12 }; 13 14 void ponp::getinput() { 15 cout << "please enter the value : "; 16 cin >> input; 17 } 18 19 void ponp::calcdisp() { 20 if (input <= 1) { 21 cout << "This is not a prime number."; 22 return; 23 } 24 25 for (i = 2; i <= input / 2; i++) { 26 if (input % i == 0) { 27 cout << "this is not a prime number."; 28 return; 29 } 30 } 31 cout << "prime"; 32 } 33 34 int main() { 35 ponp z; 36 z.getinput(); 37 z.calcdisp(); 38 return 0; 39 }