I wrote a C++ program to find if a number is prime. The program works but the issue is that it can't use large numbers with about 11 digits such as 9999999999.
Every number lower works. Can someone please point out why it would do this.
Every number lower works. Can someone please point out why it would do this.
Code:
//Program to tell if a number is a prime number
#include <iostream>
using namespace std;
void get_input(int& num);
//Get input
bool divide(int num);
//true or false
void out_put(int num);
//output data
int main()
{
cout<<"Type 0 to stop"<<endl;
int num;
while (num!=0)
{
get_input(num);
divide(num);
out_put(num);
}
return 0;
}
void get_input(int&num)
{
cout<<"Enter integer greater than 1: " ;
cin>>num;
return;
}
bool divide(int num)
{
if (num<=1)
return false;
else if ((num==2)||(num==3)||(num==5))
return true;
else if ((num%5!=0)&&(num%3!=0)&&(num%2!=0))
return true;
else
return false;
}
void out_put(int num)
{
if(divide(num))
cout<<num<<" is prime"<<endl;
else if(num==0)
cout<<"done"<<endl;
else
cout<<num<<" is not prime"<<endl;
}