What is a Prime Number?
” A Natural number greater than 1 which has only two divisor 1 and itself is called prime number “.
For Example:
5 is prime, because it has only two divisors 1 and itself.
C Code
#include <stdio.h>
#include <conio.h>
void main()
{
int num,count=0;
printf("Enter Number: ");
scanf("%d", num);
for(int i=1;i<=num;i++)
{
if(num%i==0)
{ count++; }
}
if(count==2)
{ printf("%d is a Prime Number.\n", num); }
else
{ printf("%d is Not a Prime Number.\n", num); }
getch();
return 0;
}C++ Code
#include <iostream>
#include <conio.h>
int main()
{
using namespace std;
int num,count=0;
cout << "Enter Number: "; cin >> num;
for(int i=1;i<=num;i++)
{
if(num%i==0)
{ count++; }
}
if(count==2)
{ cout<< num << " is a Prime Number.\n"; }
else
{ cout<< num << " is Not a Prime Number.\n"; }
getch();
return 0;
}Output:
Other Related Search Terms
- Code For Prime Number In C++
- Code For Prime Number In C
- C++ Programs to find Prime number
- C Programs to find Prime number
- Find all Prime numbers
- Check number is prime or not c/c++

![[C/C++] Program to Find Prime Number](https://fsconline.info/wp-content/uploads/2015/09/c-cpp-programming.jpg)

2 Comments
Thanks for your program.Its working perfectly
Ty for your appreciation :-)
Share with others as well.