0

Functions in c++

How to write a program with functions to obtain the prime numbers up to what ever the number entered by the user in c++.. Thank you

16th Dec 2017, 3:57 PM
Lakni Aloka Weerakoon
Lakni Aloka Weerakoon  - avatar
1 ответ
+ 1
You can't enter any number in C++, as the maximum number supported by unsigned long long is 2^63-1. Now, to calculate any prime number between 0 and this number, you may use this function: bool prime(unsigned long long a) { if(a == 0 || a == 1) return false; if(a == 2) return 2; for(int i=0;i<sqrt(a);i++) if(a%i==0) return false; return true; }
16th Dec 2017, 4:09 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar