Skip to content

Instantly share code, notes, and snippets.

@BeMg
Created January 13, 2016 08:32
Show Gist options
  • Save BeMg/244866c81d711ed20627 to your computer and use it in GitHub Desktop.
Save BeMg/244866c81d711ed20627 to your computer and use it in GitHub Desktop.
perfect
#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