Created
November 25, 2014 19:00
-
-
Save yamishi13/8e15d31aa03753ad1284 to your computer and use it in GitHub Desktop.
paralell primos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
const int NUMPRIMOS = 1000000; | |
clock_t start,end; | |
int CalculaPrimosFuerzaBruta() | |
{ | |
int candidato; | |
bool esprimo; | |
int cuantosprimos = 0; | |
for(candidato = 2;candidato < NUMPRIMOS;candidato++) | |
{ | |
esprimo = true; | |
for(int j = 2;j < candidato;j++) | |
{ | |
if((candidato % j) == 0) | |
{ | |
esprimo = false; | |
j = candidato; | |
} | |
} | |
if(esprimo) | |
cuantosprimos++; | |
// printf("%d\t",candidato); | |
} | |
return cuantosprimos; | |
} | |
int main(int argc, char** argv) | |
{ | |
double time_in_seconds; | |
int cuantosprimos; | |
start=clock(); | |
cuantosprimos = CalculaPrimosFuerzaBruta(); | |
end=clock(); | |
time_in_seconds=(double)(end-start)/(double)CLOCKS_PER_SEC; | |
printf("encontro %d numeros primos en %g segundos",cuantosprimos,time_in_seconds); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment