Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class prime
- {
- public:
- int num,countl=0;
- prime(int a)
- {
- num=a;
- }
- void checknumber()
- {
- int i;
- for(i=2;i<=sqrt(num);i++){
- if(num%i == 0)
- countl++;
- else
- countl = countl;
- }
- }
- void display()
- {
- if(countl==0){
- cout << "Number is prime" << endl;
- }
- else
- cout << "Number is not Prime" << endl;
- }
- };
- int main()
- {
- cout << "Input a number to check it is prime or not: ";
- int n;
- cin >> n;
- prime obj(n);
- obj.checknumber();
- obj.display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement