write the prime no program in c++?

Answer Posted / waleed

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

int prime(int);

void main()
{
clrscr();
int num,x;
cout<<"Enter the no.=";
cin>>num;
x=prime(num);
if(x==1)
{
cout<<"Number is prime";
}
else
{
cout<<"Number is not prime";
}

getch();
}

int prime(int x)
{
int k;
for(int i=2;i<x;i++)
{
if (x%i==0)
{
k=2;
}
}
if (k==2)
return 0;
else
return 1;


}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?

668


What is public, protected, private in c++?

649


What is function overloading c++?

570


What is the difference between mutex and binary semaphore?

610


What is the use of setfill in c++?

581






What is a Default constructor?

913


Is c++ slower than c?

571


Which operator cannot overload?

539


C is to C++ as 1 is to a) What the heck b) 2 c) 10

635


What do you understand by pure virtual function? Write about its use?

577


How do you compile the source code with your compiler?

613


What is meant by entry controlled loop?

656


What is difference between rand () and srand ()?

588


What is pair in c++?

624


what is upcasting in C++?

718