write the prime no program in c++?

Answer Posted / daljeet singh

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i;
char prime;
prime='Y';
cout<<"\n enter a number";
cin>>n;
for(i=2;i<=n/2;++i)
{
if(n%i==0)
{
prime='N';
break;
}
}
if(n==1)
prime='N';
if(prime=='Y')
cout<<"\n entered number is prime";
else
cout<<"\n not a prime no";
getch();
}

Is This Answer Correct ?    10 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is general form of pure virtual function? Explain?

509


What is a template in c++?

635


How java is different from c and c++?

637


What is #include c++?

567


What is an arraylist c++?

687






What is iostream in c++ used for?

549


What is an adaptor class in c++?

598


Is turbo c++ free?

617


What are protected members in c++?

619


In what situations do you have to use initialization list rather than assignment in constructors?

631


What is flush programming?

570


Explain abstraction.

616


What are the five basic elements of a c++ program?

581


What are guid? Why does com need guids?

568


Explain 'this' pointer and what would happen if a pointer is deleted twice?

600