Featured
- Get link
- X
- Other Apps
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:
#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 |
- Get link
- X
- Other Apps
Labels:
C++ program to check a number is prime or not
prime number program in c++
program to check prime number
Popular Posts
C++ program to display numbers which get reversed after multiplying by 4
- Get link
- X
- Other Apps
Comments
Post a Comment