Algoritmo para determinar números primos C++
Bueno este es el algoritmo para obtener los números primos de manera creciente y con un solo ciclo MODULARMENTE
ES TODO UN CLÁSICO DE LOS PROFESORES!!!!
ES TODO UN CLÁSICO DE LOS PROFESORES!!!!
#include
using namespace std;
bool siesP(int);
void show(int, int);
int pr(int);
int main(int argc, char *argv[])
{
int x=2, a;
cout<< "Introducir el termino a " <cin>>a;
show(x, a);
return 0;
}
void show (int z, int y)
{
while(y>0)
{
if(siesP(z)==true)
{
cout<< z << " ";
y--;
z++;
}
else
{
z++;
}
}
}
bool siesP(int z1)
{
if(pr(z1)==z1)
{
return true;
}
else
return false;
}
int pr(int z2)
{
int conta=2;
while (conta<=z2 && z2%conta!=0)
{
conta++;
}
return conta;
}