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 c++

1805


Explain Memory Allocation in C/C++ ?

643


Is it possible for the objects to read and write themselves?

651


Are vectors faster than arrays?

572


Do vectors start at 0?

596






Explain operator overloading.

608


Which is better c++ or java?

567


What is virtual methods?

663


Explain what is class definition in c++ ?

599


Can we overload operator in c++?

555


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

641


What are c++ data types?

646


What is virtual function? Explain with an example

593


Can we define a constructor as virtual in c++?

605


What is the use of c++ programming language in real life?

569