write the prime no program in c++?

Answer Posted / adnan sheikh

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

main()
{
int i,j,num;
cout<<"enter nay number";
cin>>num;
j=static_cast<int>(num/2);
for(int i=2;i<=j;i++)
{
if(!(num%i))
break;
}
if(i==(j+1))
cout<<"number is prime";
else
cout<<"number is not prime";
getch();
}

Is This Answer Correct ?    8 Yes 19 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a friend function in c++?

1020


What are c++ data types?

878


What is c++ & why it is used?

810


Can we overload operator in c++?

766


Why do we use the using declaration?

913


What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?

842


Why should you learn c++?

794


I want explanation for this assignment: how to connect mysql database using c/c++,please explain this detailly?

1793


How can I improve my c++ skills?

807


What is pointer to member?

768


What is binary object model?

767


What is the difference between ++ count and count ++?

825


What are the characteristics of friend functions?

760


Implement stack operations with pointers with appropriate exception checks.

757


Difference between overloading vs. Overriding

814