write the prime no program in c++?

Answer Posted / swapnil

/*To check whethere Entered no. is PRIME or NOT*/
#include<iostream.h>
#include<conio.h>
main()
{
int num,i;
clrscr();
cout<<"Enter the any no.="<<"\n";
cin>>num;
for(i=2;i<=num;i++)
{
if(num%i==0)
{
break;
}
}
if(i==num)
{
cout<<"The number entered is a
PRIME no.";
}
else
{
cout<<"The number entered is NOT a
PRIME no.";
}
getch();
}

Is This Answer Correct ?    74 Yes 41 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can circle be called an ellipse?

638


how to explain our contribution in the project?

3080


If I is an integer variable, which is faster ++i or i++?

593


What are the advantages of using pointers in a program?

681


I was a c++ code and was asked to find out the bug in that. The bug was that he declared an object locally in a function and tried to return the pointer to that object. Since the object is local to the function, it no more exists after returning from the function. The pointer, therefore, is invalid outside.

614






If a function doesn’t return a value, how do you declare the function?

618


Which programming language is best to learn first?

585


When should we use container classes instead of arrays?

586


Is string an object in c++?

659


If a header file is included twice by mistake in the program, will it give any error?

552


What is the this pointer?

637


What is a local variable?

581


Evaulate: 22%5 a) 2 b) 4 c) 0

670


You have two pairs: new() and delete() and another pair : alloc() and free(). Explain differences between eg. New() and malloc()

593


What does getch() do according to the ANSI C++ standard a) Reads in a character b) Checks the keyboard buffer c) Nothing in particular (Its not defined there)

602