PRIME NUMBER RANGE IN BETWEEN MIN AND MAX VALUES :
// program to illustrate prime numbers range in between min and max values
#include<stdio.h>
#define pf printf
#define sf scanf
void main()
{
int min,max,n,i,count;
pf("\nEnter min number:");
sf("%d",&min);
pf("\nEnter max number:");
sf("%d",&max);
pf("\n Prime numbers are:");
for(n=min;n<=max;n++)
{
i=1,count=0;
while( i <= n )
{
if((n % i == 0) && (n % n == 0))
count++;
i++;
}
if (count == 2)
pf("\n%d is a prime number",n);
}
}
output:
// program to illustrate prime numbers range in between min and max values
#include<stdio.h>
#define pf printf
#define sf scanf
void main()
{
int min,max,n,i,count;
pf("\nEnter min number:");
sf("%d",&min);
pf("\nEnter max number:");
sf("%d",&max);
pf("\n Prime numbers are:");
for(n=min;n<=max;n++)
{
i=1,count=0;
while( i <= n )
{
if((n % i == 0) && (n % n == 0))
count++;
i++;
}
if (count == 2)
pf("\n%d is a prime number",n);
}
}
output:
No comments:
Post a Comment