Código
#include <stdio.h>
#include <stdlib.h>
#define FALSE 0
#define TRUE !FALSE
typedef int Bool;
int longitud(void);
Bool es_primo(int num);
int main()
{
int n = longitud();
int i, num=2;
for(i=0; i<n;)
{
if(es_primo(num))
{
printf("%d ", num);
i++;
}
num++;
}
printf("\n\n");
system("pause");
return 0;
}
Bool es_primo(int num)
{
Bool b = TRUE;
int i, divisores=0;
for(i=1; i<=num; i++)
{
if(num%i == 0)
divisores++;
if(divisores > 2)
{
return b=FALSE;
}
}
return b;
}
int longitud(void)
{
int n;
printf("Cantidad de primos: ");
scanf("%d", &n);
return n;
}
Saludos.
Links Relacionados:
* Desarrollar un algoritmo para generar los primeros K primeros números primos de la serie Fibonacci.
programacion c++ numeros primos
http://foro.elhacker.net/empty-t215844.0.html
[C\C++] Dudilla con un codigo para ver si un numero es primo
http://foro.elhacker.net/empty-t186450.0.html
[C++] Pseudo Random Encryption Algorithm 1.0 RC2 by APOKLIPTICO.
http://foro.elhacker.net/empty-t233347.0.html
Esquema RSA
http://foro.elhacker.net/empty-t254640.0.html
Algoritmo numeros primos [Batch]
http://foro.elhacker.net/empty-t251824.0.html
[Batch] Algoritmo de Numeros Primos
http://foro.elhacker.net/empty-t235233.0.html
[batch] Problema extraño
http://foro.elhacker.net/empty-t219922.0.html
[batch] Descomposicion factorial
http://foro.elhacker.net/empty-t222322.0.html
Calcular numeros primos
http://foro.elhacker.net/empty-t252389.0.html
Numero no-primo terminando en 13?
http://foro.elhacker.net/empty-t252440.0.html










Autor



En línea
