declaring | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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!"; } }

27th May 2017, 11:25 AM
mei
mei - avatar
1 Answer
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.
29th May 2017, 9:14 PM
Patel