+ 2

C and Python Factorial

I write a program to calculate factorial in C and Python programming language with same logic. But I can't take factorial greater then 20 or 21 in C as it is giving me wrong answer and at factorial of 65 it give me 0 answer. But in python I was able to take factorial of even 90000 and it was taking so long to calculate factorial of 9000000 i.e., it will give me output. Why C was not be able to do that https://code.sololearn.com/csIFn2Tvbuh2/?ref=app https://code.sololearn.com/cylny74G6g66/?ref=app

27th Oct 2020, 2:14 AM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
5 Answers
+ 4
Shail Murtaza as Jan Markus said, any primitive data type of C/C++ can't be used to store value large enough for higher factorials. But you can always use arrays to tackle this problem 👇 https://code.sololearn.com/c05uyb2zjENS/?ref=app
27th Oct 2020, 12:47 PM
Arsenic
Arsenic - avatar
+ 3
Shail Murtaza factorial of 65 is beyond capacity of unsigned long long int. Unsigned long long int has capacity of 0 - 18,446,744,073,709,551,615.
27th Oct 2020, 2:50 AM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
+ 1
C program is working fine. It is also showing factorial of 65! = 9223372036854775808 (maybe correct 😅) Happy coding
27th Oct 2020, 2:36 AM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
+ 1
ツ Priyanshi ツ {PTP} This is not correct I guess Sololearn's server is better then mine PC so it is not giving 0 output. Search on Google factorial of 65 or you can use Python
27th Oct 2020, 2:43 AM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
+ 1
So, What to do?
27th Oct 2020, 10:46 AM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar