Created
January 13, 2016 08:32
-
-
Save BeMg/244866c81d711ed20627 to your computer and use it in GitHub Desktop.
perfect
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> | |
#include <stdlib.h> | |
int ans(int n){ | |
int sum=0; | |
for(int i=1; i<n; i++){ | |
if(n%i==0){ | |
sum+=i; | |
} | |
if(sum>n) | |
return 0; | |
} | |
if(sum==n) | |
return 1; | |
else | |
return 0; | |
} | |
int main(){ | |
int n; | |
scanf("%d",&n); | |
for(int i=1; i<=n; i++){ | |
if(ans(i)==1){ | |
printf("%d ",i); | |
} | |
} | |
printf("is perfect number\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment