import java.io.*;
class Prime
{
public static void main(String arg[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter a positive lower limit");
int l=Integer.parseInt(br.readLine());
System.out.println("enter a positive upper limit");
int u=Integer.parseInt(br.readLine());
for(int n=l;n<=u;n++)
{
byte flag=1;
for(int i=2;i<=(int)n/2;i++)
{
if(n%i==0)
{
flag=0;
break;
}
}
if(flag==1)
System.out.print("\t" +n);
}
}
}
Output
enter a positive lower limit
2
enter a positive upper limit
20
2 3 5 7 11 13 17 19
class Prime
{
public static void main(String arg[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter a positive lower limit");
int l=Integer.parseInt(br.readLine());
System.out.println("enter a positive upper limit");
int u=Integer.parseInt(br.readLine());
for(int n=l;n<=u;n++)
{
byte flag=1;
for(int i=2;i<=(int)n/2;i++)
{
if(n%i==0)
{
flag=0;
break;
}
}
if(flag==1)
System.out.print("\t" +n);
}
}
}
Output
enter a positive lower limit
2
enter a positive upper limit
20
2 3 5 7 11 13 17 19
this programm were solution
ReplyDelete