check whether a no is prime or not.

Answer Posted / m.shanmuga sundaram,rjnsoftwar

void main()
{
int primeNo;
int i;
bool isPrime = false;

printf("Enter a number to check prime or not\n");
scanf("%d",&primeNo);

for(i = 2; i <= primeNo / 2; i++)
{
if(primeNo % i == 0)
{
isPrime = true;
break;
}
}

if(isPrime)
printf("The number is a prime number %
d\n",primeNo);
else
printf("The number is not a prime number %
d\n",primeNo);
}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you declare A pointer to function which receives an int pointer and returns a float pointer

680


Can union be self referenced?

579


Explain rethrowing exceptions with an example?

608


Which software is best for programming?

663


State two differences between C and C++.

610






Out of fgets() and gets() which function is safe to use?

643


What is the use of default constructor?

571


What size is allocated to the union variable?

593


What is dev c++ used for?

605


What is heap sort in c++?

600


What do the header files usually contains?

632


What is const pointer and const reference?

595


What is the meaning of string in c++?

571


What is the average salary of a c++ programmer?

544


Why c++ is called oop?

596