Dev - C++ - T2

 
Vista:

T2

Publicado por Marco (1 intervención) el 09/03/2021 04:09:13
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
#include <iostream>
 
using namespace std;
 
int main()
{
    int residuo,cont, i, n;
    cout << " Introduce un numero: ";
    cin >> n;
    i=1;
    residuo=0;
    cont=0;
    do{
   residuo = n % i;
   if(residuo==0){
        cont = cont + i;}
   i++;
    }
   while(i < n);
   if(cont == n){
    cout << "El numero " << n << " Es perfecto";
   }
    if(cont != n){
    cout << "El numero " << n << " No es perfecto";
   }
   return 0;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alfil
Val: 4.344
Oro
Ha mantenido su posición en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

T2

Publicado por Alfil (1444 intervenciones) el 09/03/2021 07:52:36
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
#include <iostream>
 
bool numeroPerfecto(int numero);
 
int main()
{
    int n;
 
    std::cout << "\nNumero: ";
    std::cin >> n;
 
    if (!numeroPerfecto(n))
        std::cout << "NO ";
 
    std::cout << "Es Perfecto" << std::endl;
 
    return 0;
}
 
bool numeroPerfecto(int numero)
{
    int suma = 0;
 
    for (int i = 1; i < numero; i++)
        if (numero % i == 0)
            suma = suma + i;
 
    return suma == numero;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar