Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- unsigned t0, t1;
- /////////////////////////////////////////////////////////////////////////////////////////
- bool esPrimo(int numero) {
- if (numero == 0 || numero == 1 || numero == 4) return false;
- for (int i = 2; i < numero / 2; i++) {
- if (numero % i == 0) return false;
- }
- //cout<<"\n\t > "<<numero<<" ES PRIMO"; //COMENTAR
- return true; }
- /////////////////////////////////////////////////////////////////////////////////////////
- int main() {
- int n,primos = 0;
- bool numero = true;
- cout<<"\n\t - INGRESE LA CANTIDAD DE NUMEROS (n):\t";
- cin>>n;
- t0=clock();
- for(int i = 0; i <= n; i++){
- numero = esPrimo(i);
- if(numero == true) primos ++;
- }
- cout<<"\n\n\t - CANTIDAD DE NUMEROS PRIMOS ENTRE (0 - "<<n<<"):\t"<<primos;
- t1 = clock();
- double tiempo = (double(t1-t0)/CLOCKS_PER_SEC);
- cout<<"\n\t - TIEMPO DE EJECUCION:\t"<< tiempo << endl;
- return 0; }
Advertisement
Add Comment
Please, Sign In to add comment