Created
July 20, 2016 19:54
-
-
Save wohhie/8a5dca87a09622a08537867b2a4716d4 to your computer and use it in GitHub Desktop.
Pefect Number checking.
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
#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