Last Updated on
A Prime Number is a number which can be divided only by 1 or by itself. And it must be a whole number greater than 1. No even number, except 2, is prime number as 2 is divided by 1 or 2 only i.e by 1 or by itself. Following program check a number is prime or not. The approach is simple, we ask user to enter a number (num). Then a loop is initiated to num-1 and we apply modulus operator to determine whether it gives remainder or not. If it gives remainder 0 , it is not a prime number.
cout<<” Enter a Number which you want to determine”;
cout<<“\n\n\t”<<num<<” is not a prime number”;
cout<<“\n\n\t”<<num<<” is prime number”;
- MongoDB Operators Tutorial – What are Different Operators Available? - October 5, 2019
- MongoDB Projection Tutorial : Return Specific Fields From Query - March 9, 2019
- MongoDB Index Tutorial – Create Index & MongoDB Index Types - July 6, 2018