write the program for prime numbers?

Answer Posted / mamoon

#include<iostream.h>
#include <math.h>

void main()
{
int number;
cout<<" --------------------------------------------
-"<<endl;
cout<<" Enter a number to find if its a prime
number "<<endl;
cout<<" --------------------------------------------
-"<<endl;
cin>>number;
bool a =true;

for(int i=2;i<sqrt(number);i++) //check
untill the square root
{

if(number%i==0) // if it is
divisible it is non prime
{
a=false;
break;
}
}


if(a==false)
cout<<number<<" \nis not a prime number"<<endl;
else
cout<<number<<" \nis a prime number"<<endl;

}

Is This Answer Correct ?    0 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are loops in c?

555


What are the application of c?

652


hi... can anyone help me to make a two-dimensinal arrays in finding the sum of two elements plzzz. thnx a lot...

1451


What is the use of bitwise operator?

694


All technical questions

1514






What is the difference between ++a and a++?

701


What are data types in c language?

590


The statement, int(*x[]) () what does in indicate?

649


What are the benefits of c language?

651


Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?

2124


which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above

1140


What are examples of structures?

601


FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above

627


What is an auto variable in c?

762


Explain what is a const pointer?

643