+ 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

13th Oct 2017, 11:05 PM
Jordan Anthony
Jordan Anthony - avatar
11 Answers
+ 7
Or just use unsigned long long, so that atleast you can try printing 25!
14th Oct 2017, 2:49 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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. šŸ˜‰
13th Oct 2017, 11:14 PM
Zephyr Koo
Zephyr Koo - avatar
+ 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.
14th Oct 2017, 4:21 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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
14th Oct 2017, 4:09 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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.
14th Oct 2017, 4:23 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
Replace int with long.
13th Oct 2017, 11:13 PM
Max Ement
Max Ement - avatar
+ 2
I decided using a double gives me up to 171!
14th Oct 2017, 2:57 AM
Jordan Anthony
Jordan Anthony - avatar
+ 2
how would I go about using a different library? what is the library name?
14th Oct 2017, 4:15 AM
Jordan Anthony
Jordan Anthony - avatar
+ 2
Sweet. Thank you.
14th Oct 2017, 4:22 AM
Jordan Anthony
Jordan Anthony - avatar
+ 1
would I use <gmp.h> like <math.h> or just <gmap> like <string>
14th Oct 2017, 4:19 AM
Jordan Anthony
Jordan Anthony - avatar
+ 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
14th Oct 2017, 4:50 AM
Jordan Anthony
Jordan Anthony - avatar