write the prime no program in c++?

Answer Posted / adnan sheikh

#include<iostream.h>
#include<conio.h>

main()
{
int i,j,num;
cout<<"enter nay number";
cin>>num;
j=static_cast<int>(num/2);
for(int i=2;i<=j;i++)
{
if(!(num%i))
break;
}
if(i==(j+1))
cout<<"number is prime";
else
cout<<"number is not prime";
getch();
}

Is This Answer Correct ?    8 Yes 19 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an iterator?

691


What is the use of cmath in c++?

593


How we can differentiate between a pre and post increment operators during overloading?

600


Is it possible to provide special behavior for one instance of a template but not for other instances?

635


What is the extension of c++?

516






What is an inline function in c++?

629


How can we read/write Structures from/to data files?

621


Which software is best for coding?

576


Write about the members that a derived class can add?

571


What is the c++ code?

570


Define 'std'.

610


What is the best c c++ compiler for windows?

570


Write my own zero-argument manipulator that should work same as hex?

589


Write a note about the virtual member function?

607


Can we make copy constructor private in c++?

605