PRIME NUMBER :
A natural number (i.e. 1, 2, 3, 4, 5, 6, etc.) is called a
prime or a
prime number if it has exactly two positive divisors, 1 and the number itself.Natural numbers greater than 1 that are not prime are called
composite.
Among the numbers 1 to 6, the numbers 2, 3, and 5 are the prime
numbers, while 1, 4, and 6 are not prime. 1 is excluded as a prime
number, for reasons explained below. 2 is a prime number, since the only
natural numbers dividing it are 1 and 2. Next, 3 is prime, too: 1 and 3
do divide 3 without remainder, but 3 divided by 2 gives remainder 1. Thus, 3 is prime. However, 4 is composite, since 2 is another number (in addition to 1 and 4) dividing 4 without remainder:
- 4 = 2 · 2.
5 is again prime: none of the numbers 2, 3, or 4 divide 5. Next, 6 is divisible by 2 or 3, since
- 6 = 2 · 3.
Hence, 6 is not prime. The image at the right illustrates that 12 is not prime:
12 = 3 · 4. No even number greater than 2 is prime because by definition, any such number
n has at least three distinct divisors, namely 1, 2, and
n. This implies that
n is not prime. Accordingly, the term
odd prime refers to any prime number greater than 2. In a similar vein, all prime numbers bigger than 5, written in the usual decimal system, end in 1, 3, 7, or 9, since even numbers are multiples of 2 and numbers ending in 0 or 5 are multiples of 5.
THE PROGRAM IS :
#include<stdio.h>
#include<stdio.h>
int isprime(int);
int i,r,n,c=0;
void main()
{
printf("Enter the number \n");
scanf("%d",&n);
r=isprime(n);
if(r==1)
{
printf(" %d is a prime number \n",n);
}
else
{
printf(" %d is not a prime number \n",n);
}
getch();
}
int isprime(int x)
{
for(i=1;i<=x;i++)
{
if(x%i==0)
{
c++;
}
}
if(c==2)
{
return 1;
}
else
{
return 0;
}
}
Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)
Or else you can try this demo file and use it ...
Click HERE to download this file.
(Press ctrl+z and hit Enter to end the program)..
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...
IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!
Don't Forget to share....