Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- VPL-Ejercicio 1
- Escriba una función para generar una serie de números primos comprendidos entres 2 y N
- */
- #include<iostream>
- #include<math.h>
- using namespace std;
- bool esPrimo(int n){
- int cont=0;
- for(int i=2 ; i<=n ; i++){
- if(n%i==0)
- cont++;
- }
- if(cont==1)
- return true;
- else
- return false;
- }
- void imprimir_primos(int n){
- for(int i=2 ; i<=n ; i++){
- if(esPrimo(i))
- cout<<i<<" ";
- }
- }
- main(){
- int n;
- cin>>n;
- imprimir_primos(n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement