write the prime no program in c++?

Answer Posted / suresh kumar

#include<iostream.h>
#include<conio.h>
void main()
{
int n,k,i=1;
cout<<"enter any no to check prime";
cin>>n;
for(i=2;i<n;i++)
{
if(n%i==0)
k=2;
}
if(k==2)
cout<<"the no is not prime"<<endl;
else
cout<<"the no is prime";
getch();
}

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to give an alternate name to a namespace?

591


Explain what you mean by a pointer.

632


What is the keyword auto for?

575


If all is successful, what should main return a) 0 b) 1 c) void

558


When does a 'this' pointer get created?

624






Can the creation of operator** is allowed to perform the to-the-power-of operations?

582


In int main(int argc, char *argv[]) what is argv[0] a) The first argument passed into the program b) The program name c) You can't define main like that

617


What will the line of code below print out and why?

330


Why is c++ a mid-level programming language?

593


Why is c++ still used?

607


We all know that a const variable needs to be initialized at the time of declaration. Then how come the program given below runs properly even when we have not initialized p?

582


Why #include is used?

619


What are the uses of c++ in the real world?

564


What is the use of main function in c++?

529


Define pre-condition and post-condition to a member function in c++?

667