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

  1. Code For Prime Number In C++
  2. Code For Prime Number In C
  3. C++ Programs to find Prime number
  4. C Programs to find Prime number
  5. Find all Prime numbers
  6. Check number is prime or not c/c++
Share.

I'm a full-stack developer, specializing in the PHP, JS, Wordpress, MEAN Stack, MERN Stack & Django. I hold a high standard of quality in everything that I do.

2 Comments

Leave A Reply