This c++ program checks if a number is a prime or not. A number which is greater than 1 and can only be divided by 1 and itself are prime numbers. These prime numbers include 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 and so on. A FOR loop is implemented in this program. If the number entered by the user can be divided by another number that is within its range to give zero as the remainder then, this number is not a prime number.
#include <iostream.h>#include <math.h>
int num, a=0;
cout<<"enter a number: ";
for(int i=2;i<num;i++)//loop begins at 2 since 1 can divide any number
cout<<num<<" is a prime number";
cout<<num<<"is not a prime";
Tech blogger, SEO expert, cryptocurrency enthusiast, and freelancer are the terms that describe me. I'll rather write a thousand words than speak hundred words, and that describes my passion as a content creator.
Techlass is an online resource that focuses on the review of the latest smartphones running on the Android, iOS, and Windows Operating System. The applications for each of these OS is also our major point of focus as we aim to keep you updated with the ever-changing trends in Technology.