Perfect number:- Sum of the factorials of a individual digit is known as Perfect number
#include<stdio.h>
#include<conio.h>
void main( )
{
int no, rem, sum=0, temp, fact;
clrscr( );
printf("Enter the required number:");
scanf("%d", &no);
temp=no;
while(no>0)
{
fact=1;
for( rem= no%10 ; rem>=1; rem--)
{
fact=fact*rem;
}
sum = sum+ fact;
no = no/10;
}
if(temp == sum)
printf("\n%d is Perfect number", temp);
else
printf("\n%d is not a Perfect number", temp);
getch();
}
Output:-
Enter the required number: 145
145 is Perfect number.
No comments:
Post a Comment