Do you know what is a prime number?
A natural number greater than 1 which has only two divisors 1 and it is called a prime number. For example: 7 is a prime number. Because it has only two divisors 1 and 7 (itself).
Now I am going to tell you how to find a prime number by using C++ program. Just type these code below
A natural number greater than 1 which has only two divisors 1 and it is called a prime number. For example: 7 is a prime number. Because it has only two divisors 1 and 7 (itself).
Now I am going to tell you how to find a prime number by using C++ program. Just type these code below
//C++ Program to find Prime number
#include<iostream.h>
#include<conio.h>
void main()
{
//clrscr();
int number,count=0;
cout<<"Enter number to check it is Prime or not ";
cin>>number;
for(int a=1;a<=number;a++)
{
if(number%a==0)
{
count++;
}
}
if(count==2)
{
cout<<" PRIME NUMBER \n";
}
else
{
cout<<" NOT A PRIME NUMBER \n";
}
//getch();
}
Thanks!
No comments:
Post a Comment