factorial problem

.wap to find factorial of individual digits in a given input number and store it in an array
eg:123
output={1,4,9}

I suppose you are asking for the square of the digits.

no output is given wrong…it shud be {1,2,6}…pls solve

Simply divide the number by 10 till it reaches zero. The number of divisions is the number of digits in the number. Create an array with size equal to the number of digits and put factorials in each element.

int num=123,count,temp;

temp=num;

while(num)

{

num/=10;

count++;

}

int arr[count];

for(int i=0; i <count; i++)

{

int x=temp%10;

temp/=10;

arr[i]=factorial(x);

}

int number=123,fact=1,i,ctr=0;
int arr[5],temp=0;
while(number)
{
int quotient=number/10;
arr[i++]=quotient;
ctr++;
}
i=0;
for(i=0;i<ctr;i++)
{
temp=arr[i];
arr[i]=factorial(temp);
cout<<arr[i];
}

int factorial(int n)
{
if(n==0||n==1)
return 1;
else
return factorial(n*(n-1));
}