# C program to find  the perfect numbers between a range

## C program to find the perfect numbers between a given range

Perfect number is an Integer number. The Perfect number is equal to the sum of all its positive divisors excluding the number itself. For example: 6 is a Perfect number ( that is, 1 + 2 + 3 = 6 ), 24 is a Perfect number ( that is, 1 + 2 + 4 + 7 + 14 = 28 ) The below given C program to find the perfect numbers between a given range. Kindly check out the program to find the perfect numbers between a range.

### Program to find  the perfect numbers between range

#include<stdio.h>
int main(){
int sum=0,p,i;
int initial,final;
printf("\n Enter the initial range: ");
scanf("%d",&initial);
printf("\n Enter the final range: ");
scanf("%d",&final);
printf("\n Perfect numbers between the given range are: ");
for(i= initial; i<= final; i++){
p=1;
while(p<=(i/2)){
if(i % p == 0)
sum=sum+p;
p++;
}
if(sum==i)
printf(" %d ",i);
sum=0;
}
return 0;
}

Sample output:

Enter the initial range:   1

Enter the final range:   20

Perfect numbers between the given range are    6