URI Online Judge Solution 1161 Factorial Sum Using C, Python Programming Language.
Read two numbers M and N indefinitely. Calculate and write the sum of their factorial. Be carefull, because the result can have more than 15 digits.
Input
The input file contains many test cases. Each test case contains two integer numbers M (0 ≤ M ≤ 20) and N (0 ≤ N ≤ 20). The end of file is determined by eof.
Output
For each test case in the input your program must print a single line, containing a number that is the sum of the both factorial (M and N).
Input Sample | Output Sample |
4 4 | 48 |
Solution Using C:
#include<stdio.h>
unsigned long long Fact(int x)
{
if(x==0) return 1;
unsigned long long n=1;
while(x>0)
{
n = n*x;
x--;
}
return n;
}
int main()
{
int m,n;
while(scanf("%d%d",&m,&n) != EOF)
{
unsigned long long x;
x = Fact(m)+Fact(n);
printf("%llu\n",x);
}
return 0;
}
Comments
Post a Comment