Question:
Factorial:
Calculate the factorial for a given number.
The first line contains an integer 'T' denoting the total number of test cases. In each test cases, it contains an integer 'N'.
1<=T<=100
0<=N<=100
NOTE: It may include large numbers.
Input:
8
18
17
16
15
11
10
5
1
Output:
6402373705728000
355687428096000
20922789888000
1307674368000
39916800
3628800
120
1
Code:
#include<stdio.h>
int func()
{
int a[250];
int n;
scanf("%d",&n);
int digits=1;
a[0]=1;
int carry=0;
int i,j,temp;
//1*2*3*...*n
for(i=1;i<=n;i++)
{
//120*6=720
for(j=0;j<digits;j++)
{
temp=a[j]*i+carry;
//0*6+0 =0,0,
//2*6+0=12 =1,2
//1*6+1=7 =0,7
a[j]=temp%10;
//the last diigit of the multiplication
//2 in 2*6=12
carry=temp/10;
}
while(carry>0)
{
a[digits]=carry%10;
carry=carry/10;
digits++;
}
}
for(i=digits-1;i>=0;i--)
{
printf("%d",a[i]);
}
printf("\n");
}
int main()
{
int cases,i;
scanf("%d",&cases);
for(i=0;i<cases;i++)
{
func();
}
return 0;
}
college-party-guide One of the most important rituals for students in college is to throw the most memorable student dorm celebration.
ReplyDeletefactorial hundred In the last few days, the “factorial of 100” is one of the top subjects and a lot of maths geeks compute it using voice assistants such as Alexa, Shiri, etc.
factorial hundred In the last few days, the “factorial of 100” is one of the top subjects and a lot of maths geeks compute it using voice assistants such as Alexa, Shiri, etc.
gigolo The term”gigolo” usually refers to the person who lives an arranged lifestyle that includes many of these relationships in a series, rather than having any other support system.
y2mate.com y2mate.com is a well-known password management system. It lets you download all your favourite videos and audios.
IGTools.net The term”gigolo” usually refers to the person who lives an arranged lifestyle that includes many of these relationships in a series, rather than having any other support system.
sniffies Sniffies isn’t bookmarked on my phone, however I’ve been logged in enough that the web target will auto-complete on my personal browser.