write the program for prime numbers?

Answer Posted / jassneet anand

import java.*;

class prime
{
public static void main(String args[])
{
int number=__;//"you wish to check ";
int flag=0;
for(i=2;i<=(int)(Math.sqrt(number));i++)
{
if(number%i==0)
{
System.out.println("Not a Prime Number");
flag=1;
break;
}
}
if(flag==0)
System.out.println("Prime Number");
}
}

Is This Answer Correct ?    12 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]

629


how to write optimum code to divide a 50 digit number with a 25 digit number??

2755


Why do we use & in c?

589


Which is best book for data structures in c?

597


What are the preprocessor categories?

638






What is the mean of function?

647


What is data structure in c programming?

572


please send me the code for multiplying sparse matrix using c

1724


What is the difference between near, far and huge pointers?

628


Is return a keyword in c?

598


Is that possible to add pointers to each other?

898


Explain the difference between ++u and u++?

635


Tell me about low level programming languages.

642


Explain what is operator promotion?

633


c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above

730