This C++ program asks the user to input a number and then determines if it is a prime number or not. It divides the input number by increments of 2 up to half the number, and counts the number of times it is evenly divisible. If the count is 0, it outputs that the number is prime, otherwise it outputs that it is not prime.
This C++ program asks the user to input a number and then determines if it is a prime number or not. It divides the input number by increments of 2 up to half the number, and counts the number of times it is evenly divisible. If the count is 0, it outputs that the number is prime, otherwise it outputs that it is not prime.
This C++ program asks the user to input a number and then determines if it is a prime number or not. It divides the input number by increments of 2 up to half the number, and counts the number of times it is evenly divisible. If the count is 0, it outputs that the number is prime, otherwise it outputs that it is not prime.
int main() { int n,d,a=0; cout<<"Enter any Number to find wether it is Prime Number or Not: "; cin>>n; d=n/2; for(int i=2;i<=d;i++) { if(n%i==0) a++; } if(a==0) { cout<<"Prime Number"<<endl; } else cout<<"Not a Prime Number"<<endl; return 0; }