Advertisement
Abelsor

VPL - Ejercicio 1

Mar 8th, 2022
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. /*
  2.                                             VPL-Ejercicio 1
  3.         Escriba una función para generar una serie de números primos comprendidos entres 2 y N
  4. */
  5. #include<iostream>
  6. #include<math.h>
  7. using namespace std;
  8. bool esPrimo(int n){
  9.     int cont=0;
  10.     for(int i=2 ; i<=n ; i++){
  11.         if(n%i==0)
  12.             cont++;
  13.     }
  14.     if(cont==1)
  15.         return true;
  16.     else
  17.         return false;
  18.  
  19. }
  20.  
  21. void imprimir_primos(int n){
  22.     for(int i=2 ; i<=n ; i++){
  23.         if(esPrimo(i))
  24.             cout<<i<<" ";
  25.     }
  26. }
  27.  
  28. main(){
  29.     int n;
  30.     cin>>n;
  31.     imprimir_primos(n);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement