473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Large Factorials in C++

Can anyone tell me how to get large fatorials in c++...in c++ i am getting the ouput upto maximum of 20!
any please help how to solve this issue.
Oct 7 '14 #1

✓ answered by donbock

The problem is that factorials quickly get too large to be represented in the standard C integer types.
  • unsigned 8-bits can hold at most 5!
  • unsigned 16-bits can hold at most 8!
  • unsigned 32-bits can hold at most 12!
  • unsigned 64-bits can hold at most 20!
  • Excel formula for bits required to hold n!: ROUNDUP(LOG(FACT(n),2),0)

4 1311
donbock
2,426 Expert 2GB
The problem is that factorials quickly get too large to be represented in the standard C integer types.
  • unsigned 8-bits can hold at most 5!
  • unsigned 16-bits can hold at most 8!
  • unsigned 32-bits can hold at most 12!
  • unsigned 64-bits can hold at most 20!
  • Excel formula for bits required to hold n!: ROUNDUP(LOG(FACT(n),2),0)
Oct 7 '14 #2
@dinbock:
i haven't understood the last statement "ROUNDUP(LOG(FACT(n),2),0)"
could u please explain it briefly
Oct 7 '14 #3
weaknessforcats
9,208 Expert Mod 8TB
You can express a large number as a string or as an array.

In C++ you would design a class to contain the array with member functions that work with the array to let you do math on the elements.
Oct 7 '14 #4
donbock
2,426 Expert 2GB
@saiavinashiitr -that last line is an Excel formula. For example, to find out how many bits it takes to hold the value of 100!, type this into an Excel spreadsheet cell: =ROUNDUP(LOG(FACT(100),2),0)
  • FACT(100) returns the value of 100!, call it a.
  • LOG(a,2) returns the base 2 logarithm of 100!., call it b.
  • ROUNDUP(b,0) rounds the logarithm up to the next integer.
Oct 8 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
0
by: Dirk Försterling | last post by:
Hi all, a few days ago, I upgraded from PostgreSQL 7.2.1 to 7.4, following the instructions in the INSTALL file, including dump and restore. All this worked fine without any error (message). ...
3
by: julry | last post by:
I need to compute factorials, but I hit a limit around 170!. Is there anyway to handle numbers larger than the float data type can handle? Thanks.
13
by: bob | last post by:
If you were designing a class to represent very large integers in C++, what kind of internal representation would be best?
5
by: skyline789 | last post by:
Hello guys! Just started learning java and kind of struggling my way through the code of factorials. Well, basically we were asked to write a code that displays the factorials of numbers from 1 to...
59
by: Py-Fun | last post by:
I'm stuck trying to write a function that generates a factorial of a number using iteration and not recursion. Any simple ideas would be appreciated.
4
by: Voltem | last post by:
Hey everyone I just registered. Seems like a nice community and all the other sentimental BS :). So my problem in a nutshell is I wanna write a programme that calculates Large factorials (lets say...
11
by: ladan | last post by:
hi i have to write a c++ program that can calculate big factorials using a vector sized 17(for example c)and c can hold 8 digits i need help plz help me
5
by: catgreg | last post by:
I am currently working on a c++ program that computes factorials and I can't get it to work for some reason, i could really use a hint, this is what I have thus far for code: #include<iostream>...
0
by: stdq | last post by:
Hello, everyone. In this article, I'll show you a way to print a table of the factorials of the integers in the range 0-20. Please note there is no warranty when it comes to using the code here...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.