Advertisement
Imran1107048

Class & Object for Check Prime

Apr 19th, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class prime
  5. {
  6. public:
  7. int num,countl=0;
  8.  
  9. prime(int a)
  10. {
  11. num=a;
  12. }
  13.  
  14. void checknumber()
  15. {
  16. int i;
  17. for(i=2;i<=sqrt(num);i++){
  18. if(num%i == 0)
  19. countl++;
  20. else
  21. countl = countl;
  22. }
  23. }
  24.  
  25. void display()
  26. {
  27. if(countl==0){
  28. cout << "Number is prime" << endl;
  29. }
  30. else
  31. cout << "Number is not Prime" << endl;
  32. }
  33. };
  34.  
  35. int main()
  36. {
  37. cout << "Input a number to check it is prime or not: ";
  38. int n;
  39. cin >> n;
  40. prime obj(n);
  41. obj.checknumber();
  42. obj.display();
  43. return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement