Perfect number:- Sum of the factorials of a individual digit is known as Perfect number
Ex:- 145 = 1! + 4! + 5!
=> 145 = 1 + 24 + 120
==> 145 = 145
So '145' is a Perfect number.
#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before 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.
Note:- If u have any doubt regarding this program or logic, please feel free to contact me.
Monday, February 16, 2009
Subscribe to:
Post Comments (Atom)
it is a wrong program
ReplyDeletei didnot get the output
ReplyDeletehey,, manju check ur program once .. Its working fine. I thk ur done the mistake in header section ie.,
ReplyDelete#include
#include