PRIME NUMBER:
A NATURAL NUMBER GREATER THAN ONE HAS ANY OTHER DIVISORS EXCEPT 1 AND ITSELF IN OTHER WORDS WE CAN SAY WHICH HAS ONLY TWO DIVISORS 1 AND NUMBER ITSELF
FOR EXAMPLE: 5 DIVISORS ARE 1 AND 5
FOR EXAMPLE : 7 DIVISORS ARE 1 AND 7
PROGRAM:
// program to illustrate prime number
#include<stdio.h> // header section
int count; // global section
void main()
{
int n,i=1;
printf("Enter any number:");
scanf("%d",&n);
while( i <= n )
{
if((n % i == 0) && (n % n == 0))
count++;
i++;
}
if (count == 2)
printf("%d is a prime number",n);
else
printf("%d is not a prime number",n);
}
output:
A NATURAL NUMBER GREATER THAN ONE HAS ANY OTHER DIVISORS EXCEPT 1 AND ITSELF IN OTHER WORDS WE CAN SAY WHICH HAS ONLY TWO DIVISORS 1 AND NUMBER ITSELF
FOR EXAMPLE: 5 DIVISORS ARE 1 AND 5
FOR EXAMPLE : 7 DIVISORS ARE 1 AND 7
PROGRAM:
// program to illustrate prime number
#include<stdio.h> // header section
int count; // global section
void main()
{
int n,i=1;
printf("Enter any number:");
scanf("%d",&n);
while( i <= n )
{
if((n % i == 0) && (n % n == 0))
count++;
i++;
}
if (count == 2)
printf("%d is a prime number",n);
else
printf("%d is not a prime number",n);
}
output:
No comments:
Post a Comment