Hi all,
please look at the code below, its to generate all such numbers which have the sum of factorial of individual digits equal to the number itself (eg 145=1!+4!+5!)
CODE
#include<iostream.h>
#include<conio.h>
#include<math.h>
long facto(long n1) {
if(n1==0||n1==1)
return 1;
else
return n1*facto(n1-1);
}
void check(long num) {
long temp,t,x,i,sum=0;
for(i=0;(num<=pow(10,i));i++) { // to get the total no of digits
}
t=i-1;
for(i=t;i>=0;i--) { //to get each individual digit
x=pow(10,i);
temp=num/x;
sum+=facto(temp);
num%=x;
}
cout<<"\nSUM"<<sum;
if(sum==num)
cout<<num;
}
void main() {
cout<<"\nThe numbers for which the factorial of digits is equal to its value are : \n";
for (long a=1;a<100000;a++) {
check(a);
}
getch();
}
Whats the mistake i am doing, i getting pow overflow error, and then TC crashes . Doesnt work on BCC 4.5 either.
Please help.