Skip to main content

Featured

functions in Python

C++ program to check a number is prime or not

//Following program checks any given number for prime number. 
#include<iostream.h>
void main()
{
int x,flag=1;
cout<<"\nEnter A Number\n";
cin>>x;
for(int i=2;i<x/2;i++)
{
if(x%i==0)
{flag=0; break;}
}
if(flag==1)
cout<<"Prime Number";
else if(flag==0)
cout<<"Not Prime";
}

OUTPUT:
C++ program to check a number is prime or not

Comments

Popular Posts