Write a C++ program to check whether a number is prime or not.
Answers
Answered by
1
include
using namespace std;
int main(){
int num;
bool flag = true;
cout<<"Enter any number(should be positive integer): ";
cin>>num;
for(int i = 2; i <= num / 2; i++) {
if(num % i == 0) {
flag = false;
break;
}
}
if (flag==true)
cout< else
cout< return 0;
using namespace std;
int main(){
int num;
bool flag = true;
cout<<"Enter any number(should be positive integer): ";
cin>>num;
for(int i = 2; i <= num / 2; i++) {
if(num % i == 0) {
flag = false;
break;
}
}
if (flag==true)
cout< else
cout< return 0;
Similar questions