Social Icons

banner image

All Prime Numbers less than 600

Question:
Write a program to print a table of all prime numbers less than 600. Use the sieve method;
take the rst 600 integers and cross out all those that are multiples of 2, 3, 5, etc. until only
primes remain, then print out the numbers.
solution
class primesnumber
{
public static void main(String[] args)
{
int n,p;

for(int i=2;i<600;i++)
{
p=0;
for(int j=2;j<i;j++)
{
if(i%j==0)
p=1;
}
if(p==0)
System.out.println(i);
}
}
}
All Prime Numbers less than 600 All Prime Numbers less than 600 Reviewed by Shobhit Goel on January 27, 2016 Rating: 5

No comments:

Airtel Hackaton 2017

Powered by Blogger.