Write a program to check given number is perfect number or no

// Write a program to check given number is perfect number or not
// Eg: 6 -> Factors: 1,2,3; sum: 6 -> Palindrome
#include
int main(){
int i,inp,sum=0;
printf("Enter a number:");
scanf("%d",&inp); // input from user
if(inp>0) {
for(i=0;i<inp;i++){
if(inp%i==0)
sum=sum+i;
        }
if(sum==inp) // checking if perfect number
printf("Given number is perfect number\n");
else
printf("Given number is not perfect number\n");
}
else{
printf("Given number is not perfect number\n");}
return 0;
}

No comments:

Post a Comment