Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- bool esPrimo(int); // Funcion
- void imprimir_primos(int); // Procedimiento
- int main(){
- int n;
- cin>>n;
- imprimir_primos(n);
- }
- ///// Funciones //////////
- bool esPrimo(int n){
- int cont = 0;
- for(int i=1 ; i<=n ; i++){
- if(n%i==0){
- cont++;
- }
- }
- if(cont==2){
- return true;
- }
- return false;
- }
- void imprimir_primos(int n){
- for(int i=2 ; i<=n ; i++){
- if(esPrimo(i))
- cout<<i<<" ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement