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

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

644


How many levels of pointers have?

593


what is the differnce between programing langauge and tool? is sas is a programing langauge r tool?

1904


What are the application of c?

646


When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?

586






How many bytes are occupied by near, far and huge pointers (dos)?

667


When should a type cast not be used?

624


Write a program to swap two numbers without using third variable in c?

616


Where does the name "C" come from, anyway?

643


Write a program on swapping (100, 50)

636


In C language, a variable name cannot contain?

743


What are reserved words with a programming language?

602


What is advantage of pointer in c?

689


State two uses of pointers in C?

638


What is context in c?

541