0
declaring
if(x <= 1977571 && x != 0){ for(int i=2;i<=x;i++){ if(x%i==0){ cout<<x<<" is not prime."; } } if( i == x){ cout<<x<<" is prime!"; } }
1 Odpowiedź
0
you can use following data type for large numbers:
long int x;
long long int x;
and if number is only expected to be positive :
unsigned long int x;
unsigned long long int x;
Hope that helps.Thanks.
Suggestion:
you can make your loop efficient by checking if the given number is even or not(divisible by 2). If not then run a loop which jumps by two by all odd numbers which makes your code twice efficient then this one.
Hope that helps.Thanks.