#include <stdio.h>
int main(){
int number = 0;
int key = 0;
int a[20] = {0};
int i;
printf("Input a number:");
scanf("%d",&number);
printf("Factors of %d are:",number);
if(isPerfectNumber(number,&key,a)){
for(i = 0;i < key;i++)
printf("%d ",a[i]);
printf("\n%d has %d factors",number,key);
}
else
printf("%d is not a perfect number\n",number);
return 0;
}
int isPerfectNumber(int number,int *key,int a[]){
int i;
int val = number/2;
int m = 0;
int t = number;
for(i = 1;i <= val;i++){
if(number%i == 0){
a[m] = i;
m++;
t -= i;
}
}
*key = m;
if(t == 0)
return 1;
else
return 0;
}
int main(){
int number = 0;
int key = 0;
int a[20] = {0};
int i;
printf("Input a number:");
scanf("%d",&number);
printf("Factors of %d are:",number);
if(isPerfectNumber(number,&key,a)){
for(i = 0;i < key;i++)
printf("%d ",a[i]);
printf("\n%d has %d factors",number,key);
}
else
printf("%d is not a perfect number\n",number);
return 0;
}
int isPerfectNumber(int number,int *key,int a[]){
int i;
int val = number/2;
int m = 0;
int t = number;
for(i = 1;i <= val;i++){
if(number%i == 0){
a[m] = i;
m++;
t -= i;
}
}
*key = m;
if(t == 0)
return 1;
else
return 0;
}