Skip to content

Instantly share code, notes, and snippets.

@wohhie
Created July 20, 2016 19:54
Show Gist options
  • Save wohhie/8a5dca87a09622a08537867b2a4716d4 to your computer and use it in GitHub Desktop.
Save wohhie/8a5dca87a09622a08537867b2a4716d4 to your computer and use it in GitHub Desktop.
Pefect Number checking.
#include <stdio.h>
int main() {
int num, rem;
int sum = 0;
int i;
printf("Enter a number: ");
scanf("%d", &num);
for (i = 1; i <= (num - 1); i++) {
rem = num % i;
if (rem == 0) {
sum = sum + i;
}
}
if (sum == num) {
printf("\nThis is a perfect number.");
}
else {
printf("\nThis is not a perfect number.");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment