+ 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
5 ответов
+ 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
+ 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.
+ 1
C program is working fine.
It is also showing factorial of 65! = 9223372036854775808 (maybe correct 😅)
Happy coding
+ 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
+ 1
So, What to do?