Write c program to take numbers from the user and print all prime numbers between the given range.
In this program, taking lower range and higher range from the user and display all prime numbers between a given range.
#include<stdio.h>
int main()
{
int i,j,LR,HR,b;
printf("enter the lower range:");
scanf("%d",&LR);
printf("enter the higher range:");
scanf("%d",&HR);
printf("prime numbers between %d to %d are:",LR,HR);
for(i=LR;i<=HR;i++)
{
b=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
b=b+1;
}
}
if(b==2)
printf("%d \t",i);
}
return 0;
}
enter the lower range:10 enter the higher range:20 prime numbers between 10 to 20 are:11 13 17 19
LR
and higher-range i.e UR
from the user and store them in an LR
and HR
.In this program, taking higher range from user and print all prime number between 1 to given range.
#include<stdio.h>
int main()
{
int i,j,n,b;
printf("enter the higher range:");
scanf("%d",&n);
printf("\n prime number are:");
for(i=1;i<=n;i++)
{
b=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
b=b+1;
}
}
if(b==2)
printf("%d \t",i);
}
return 0;
}
enter the higher range:10 prime number are:2 3 5 7