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
What are loops in c?
What are the application of c?
hi... can anyone help me to make a two-dimensinal arrays in finding the sum of two elements plzzz. thnx a lot...
What is the use of bitwise operator?
All technical questions
What is the difference between ++a and a++?
What are data types in c language?
The statement, int(*x[]) () what does in indicate?
What are the benefits of c language?
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?
which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above
What are examples of structures?
FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above
What is an auto variable in c?
Explain what is a const pointer?