+ 1
How could I make the program print factorials past 12? It wont print the proper value for 13!.
Factorial program to 12! https://code.sololearn.com/cEeT3g2g8S8L/?ref=app
11 odpowiedzi
+ 7
Or just use unsigned long long, so that atleast you can try printing 25!
+ 6
We need more than 31 bits to store 13! and int takes 1 bit to store the sign of number. You may consider to use
unsigned long int
with larger capacity and fully utilize the bits to represent the number. 😉
+ 6
The GNU Multi-Precision Library.
Download it here: https://gmplib.org/
If you're using CodeBlocks, you will need to add the libraries under Compiler-> Search Directories -> include -> the Include folder of the library downloaded.
Similarly, you need to add the libraries under linker in the same tab.
+ 5
@Jordan Anthony
Don't use double. The answers are not correct. Everytime the double number gets multiplied, it adds to itself a small modulus error, which then becomes larger and larger, and will add up to your result, making it incorrect.
I learnt this the hard way, and thus started using the GNU Multi-Precision arithmetic library for such tasks.
See this, if possible:
https://www.sololearn.com/discuss/348499/?ref=app
+ 5
You need to download the headers and then use it either after binding it with your IDE and then including <gmp.h> in your program, or just copying the headers to your current source location and including "gmp.h" in your program.
+ 2
Replace int with long.
+ 2
I decided using a double gives me up to 171!
+ 2
how would I go about using a different library? what is the library name?
+ 2
Sweet. Thank you.
+ 1
would I use <gmp.h> like <math.h> or just <gmap> like <string>
+ 1
I have code runner 2 on my Mac. do you know how to add it to that? I have all of the gmp files downloaded but can't figure out how to add it to compiler