C++ Program to a Number is Prime or Not

Assume that you want to check whether the No. is prime or not. Write a Program that ask for a No. representing. When it finishes the calculation, the program asks if the user wants to do another calculation. The response may be yes or no (Y\N).
- C – Program to Find the Factorial of Entered Number
- C – Find Prime Number from 1 to 100 Using the Function
- Comparison of While, Do-While and For Loops
- C – If, If-else and Nested If-else Statements
- C++ Prints the Sum, Difference, Products, Quotient Remainder
Source Code
#include<iostream> #include<conio.h> using namespace std; class prime { int d; public: void getn() { cout<<"Enter a number :"; cin>>d; } void isprime() { int i,flag=0; for(i=2;i<=(d/2);i++) { if((d%i)==0) { flag=1; break; } } if(flag) cout<<"Composite!!"; else cout<<"Prime!!"; } }; int main() { prime a; char ch; do { a.getn(); a.isprime(); cout<<endl<<"Do you wish to do another calculation (Y/N)?"; cin>>ch; } while(ch!='N') ; }