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
i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none
How many levels of pointers have?
what is the differnce between programing langauge and tool? is sas is a programing langauge r tool?
What are the application of c?
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
How many bytes are occupied by near, far and huge pointers (dos)?
When should a type cast not be used?
Write a program to swap two numbers without using third variable in c?
Where does the name "C" come from, anyway?
Write a program on swapping (100, 50)
In C language, a variable name cannot contain?
What are reserved words with a programming language?
What is advantage of pointer in c?
State two uses of pointers in C?
What is context in c?