-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesprimo
More file actions
42 lines (39 loc) · 727 Bytes
/
esprimo
File metadata and controls
42 lines (39 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <iostream>
using namespace std;
int cuentadivisores(int numero);
bool esprimo(int numero);
int main()
{
int numero;
cout<<"Ingresa el numero";
cin>>numero;
/*cout<<"Numero de divisores"<<cuentadivisores(numero)<<endl;
if(esprimo(numero)==true)
cout<<"si es primo";*/
for(int i=1;i<=numero;i++)
{
if(esprimo(i)==true)
cout<<i<<endl;
}
return 0;
}
int cuentadivisores(int numero)
{
int contador=0;
for(int i=1;i<=numero;i++)
{
if(numero%i==0)
{
contador++;
}
}
return contador;
}
bool esprimo(int numero)
{
if(cuentadivisores(numero)==2)
return true;
else
return false;
}