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
How can I run c program?
What is the scope of an external variable in c?
What is the difference between procedural and functional programming?
What are the advantages of using Unions?
Describe the difference between = and == symbols in c programming?
Is stack a keyword in c?
If one class contains another class as a member, in what order are the two class constructors called a) Constructor for the member class is called first b) Constructor for the member class is called second c) Only one of the constructors is called d) all of the above
What is main return c?
What is the use of static variable in c?
What does c mean in standard form?
Can you apply link and association interchangeably?
Can you think of a logic behind the game minesweeper.
The number of bytes of storage occupied by short, int and long are a) 2, 2 and 4 b) 2, 4 and 4 c) 4, 4 and 4 d) none
What is openmp in c?
Explain what is output redirection?