C Program For Perfect Number
C Program :
/* Aim: Write a c program to check the perfect number. Example: 6 (1+2+3),128(1+2+4+7+14) #include<stdio.h> void main() { int i=1,num,sum=0; printf("\n Enter any number:- "); scanf("%d",&num); do { if (num%i==0) { sum+=i; } i++; }while(i<num); if (num==sum) { printf("\n %d is a perfect number",num); } else { printf("\n %d is not a perfect number",num); } printf("\n \n"); } // End of the code
/* Output of above code:-
[root@localhost ~]# cc L21.c
[root@localhost ~]# ./a.out
Enter any number:- 28
28 is a perfect number */
Comments