Skip to content

Instantly share code, notes, and snippets.

@ahoulgrave
Created May 22, 2013 19:22
Show Gist options
  • Save ahoulgrave/5630171 to your computer and use it in GitHub Desktop.
Save ahoulgrave/5630171 to your computer and use it in GitHub Desktop.
Chequear si un número es perfecto
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int i, num, sumaDeDivisores;
i = 1;
num = 6;
sumaDeDivisores = 0;
printf("Ingrese un numero:");
scanf("%d", &num);
while (i <= num-1) {
if (num%i == 0) {
sumaDeDivisores = sumaDeDivisores+i;
}
i = i+1;
}
if (num == sumaDeDivisores) {
printf("\nEl numero %d es perfecto\n\n", num);
} else {
printf("\nEl numero %d no es perfecto\n\n",num);
}
system("PAUSE");
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment