GeeksforGeeks » Interview Questions
Microsoft Interview Question for Software Testing (0 - 2 Years) about CPuzzles
(2 posts)-
implement factorial, do remeber to handle the overflow case, which is actually the key point, otherwise this problem will be too simple
-
Take an array to multiply to avoid overflow condition.
suppose 6! is to be found.int main()
{
int arr[20]={6},n=6,i,top=0,j,temp;for(i=n-1;i>0;i--)
{
j=0;temp=0;
while(j<=top)
{
temp=arr[j]*i+temp;
arr[j]=temp%10;
temp=temp/10;
j++;
}
if(temp>0)
arr[++top]=temp;
}
for(i=top;i>=0;i--)
printf("%d",arr[i]);
return 0;
}
Reply
You must log in to post.