Advertisement
Abelsor

S4_Ejercicio_1

Mar 1st, 2023 (edited)
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool esPrimo(int); // Funcion
  6. void imprimir_primos(int); // Procedimiento
  7.  
  8. int main(){
  9.    
  10.     int n;
  11.  
  12.     cin>>n;
  13.    
  14.     imprimir_primos(n);
  15.    
  16.    
  17. }
  18.  
  19. ///// Funciones  //////////
  20. bool esPrimo(int n){
  21.     int cont = 0;
  22.     for(int i=1 ; i<=n ; i++){
  23.         if(n%i==0){
  24.             cont++;
  25.         }
  26.     }
  27.     if(cont==2){
  28.         return true;
  29.     }
  30.    
  31.     return false;
  32. }
  33.  
  34. void imprimir_primos(int n){
  35.    
  36.     for(int i=2 ; i<=n ; i++){
  37.         if(esPrimo(i))
  38.             cout<<i<<" ";
  39.     }
  40. }
  41.  
  42.  
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement