Last active
December 15, 2015 04:38
-
-
Save GusGA/5202614 to your computer and use it in GitHub Desktop.
Función escrita en C, que valida si un número es perfecto o no.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Según la teoria: | |
//Un número perfecto es un número natural que es igual a la suma de sus divisores propios positivos, | |
//sin incluirse él mismo. | |
int numeroperfecto (int valor){ | |
int temp = (valor - 1); | |
int perfecto = 0; | |
do { | |
if (valor % temp == 0){ | |
perfecto += temp; | |
} | |
--temp; | |
} while (temp > 0); | |
if (perfecto == valor){ | |
printf("El numero %d es perfecto", valor); | |
}else{ | |
printf("El numero %d no es perfecto",valor); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment