FCTRL2 - Small factorials


You are asked to calculate factorials of some small positive integers.

Input

An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.

Output

For each integer n given at input, display a line with the value of n!

Example

Sample input:
4
1
2
5
3

Sample output:

1
2
120
6

hide comments
krrish0: 2019-11-08 11:37:37

#include <iostream>
#include <iomanip>

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

int main() {
int test_case{0},num1{0};
std::cin >>test_case;
for (int i = 0; i < test_case; ++i){
std::cin >> num1;
std::cout << std::setprecision(0);
std::cout << std::fixed;
std::cout <<factorial(num1)<< std::endl;
}
}

What is the problem in this above program . I don't get it.

ubc_123: 2019-09-29 15:00:26

yea use an array for storing large numbers , : ) to overcome overflow

dhia01: 2019-07-26 12:13:58

array method

Last edit: 2019-07-26 14:18:51
mahesh_1997: 2019-07-17 19:23:01

Initially assumed that we must use java or other languages to calculate factorial of 100
this is my 1st ever program accepted in C
learnt a new technique thank you

pretam9: 2019-07-09 19:41:38

why my code using dp is given WA?

h_7: 2019-06-26 10:15:51

i got the Test cases correct but got a wrong answer...

doctor_ojha01: 2019-06-23 11:35:15

i try my code in python it works
for k in range(int(input())):
f=1
n=int(input())
for i in range(1,n+1):
f=f*i
print(f)

vurise18: 2019-06-15 05:41:56

any other solution than the biginteger?

Last edit: 2019-06-15 05:46:49
tk_000: 2019-06-10 02:33:55

tusharupadhyay
it is correct for small positive numbers
but for large numbers such as 100,99,98 it is giving wrong result as range of int excedded

pyskmr: 2019-05-30 19:39:57

python is a shit language,
i did it via python with no logic at all

Last edit: 2019-05-30 19:40:06

Added by:adrian
Date:2004-05-28
Time limit:1s
Source limit:2000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All