"KEEP LEARNING, DON'T STOP."
"KEEP LEARNING, DON'T STOP."
In this section you will learn how to check whether a given number is prime or not. We are performing looping operation on it for checking a number is prime or not.
A number that is divisible only by itself and 1 is called prime number.
2, 3, 5, 7, 11, 13, 17 etc..
#include<iostream.h> #include<conio.h> //PRIME NUMBER PROGRAM void main() { int num,i,p=0; clrscr(); cout<<"ENTER A NUMBER:- "; cin>>num; for(i=2;i<=num/2;i++) { if(num%i==0) { p++; break; } } if(p==0 && num!= 1) { cout<<" IS PRIME NUMBER."<<num; } else { cout<<" IS NOT A PRIME NUMBER."<< num; } getch(); }
ENTER A NUMBER:- 7 7 IS PRIME NUMBER.