#include <iostream>
#include <math.h>
using namespace std;
bool prime(int);
int main()
{
int a=0;
do {
cout<<"please enter a number larger than two: ";
cin>>a;
} while (a <= 2);
for(int number = 2; number <= a; number++){
bool isPrime = prime(number);
if (isPrime)
{
cout<< endl << number << endl;
}
}
}
bool prime(int number)
{
for(int i = 2; i <= sqrt(number); i++)
{
if (number % i == 0){
return false;
}
}
return true;
}
So this is my code. But I want to change my output . Instead of giving me the list of prime number I want it to change into True or False
Example:
Input 5
Output True
Input 10
Output False
I do some searching on the internet but I have no idea how to cover it into my code without doing it again
so after I change it. It gives me this
Input: 5
Output:
2- true
3- true
4- false
5 -True
But It doesnt what I mean. I want it is like Prime number checker
like If u enter 5 it will give you the answer " True it is prime number"
or if u enter 6 it will give you " False it is not prime number"
#include <iostream>
#include <cmath>
usingnamespace std;
bool prime(int);
int main()
{
int a=0;
do {
cout<<"please enter a number larger than two: ";
cin>>a;
} while (a <= 2);
cout << boolalpha << prime(a) << endl;
}
bool prime(int number)
{
for (int i = 2; i <= sqrt(double(number)); i++)
{
if (number % i == 0)
{
returnfalse;
}
}
returntrue;
}