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

Explain how overloading takes place in c++?

579


If horse and bird inherit virtual public from animal, do their constructors initialize the animal constructor? If pegasus inherits from both horse and bird, how does it initialize animal’s constructor?

645


When can I use a forward declaration?

626


What is one dimensional array in c++?

584


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

613






Write down the equivalent pointer expression for referring the same element a[i][j][k][l]?

708


What is a pdb file?

544


Which c++ operator cannot overload?

556


What relational operators if statements in c++?

646


What is a multiset c++?

555


When one must use recursion function? Mention what happens when recursion functions are declared inline?

653


Where do I find the current c or c++ standard documents?

585


What is searching?

660


Write a program to encrypt the data in a way that inputs a four digit number and replace each digit by (the sum of that digit plus 7) modulus 10. Then sweep the first digit with the third, second digit with the fourth and print the encrypted number.

2097


What is tellg () in c++?

727