write the prime no program in c++?

Answer Posted / rajan maheshwari

#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a,c=0,i=2;
cout<<"Enter A Number = ";
cin>>a;
while(i<=a/2)
{
if(a%i==0)
{c=0;
break;}
else
{i++;
c=1;
}}
if(c==1||a==2||a==3)
cout<<"\nPrime Number";
else
if(a==1)
cout<<"\nNeither Prime Nor Composite";
else
cout<<"\nNot a Prime Number";
getch();
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Difference between a homogeneous and a heterogeneous container

667


What is runtime polymorphism in c++?

595


Difference between pass by value and pass by reference?

608


Write a program to add three numbers in C++ utilizing classes.

627


what is the difference between linear list linked representaion and linked representation? what is the purpose of representing the linear list in linked represention ? is it not avoiding rules of linear represention?

1749






How do I exit turbo c++?

587


What is null pointer and void pointer and what is their use?

591


What is the correct syntax for inheritance a) class aclass : public superclass b) class aclass inherit superclass c) class aclass <-superclass

693


What is abstraction in c++ with example?

565


What is an object in c++?

616


Show the declaration for a static member variable.

534


How is data hiding achieved in c++?

577


What is c++ array?

557


Why is it necessary to use a reference in the argument to the copy constructor?

637


How much do c++ programmers make?

569