473,385 Members | 1,320 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,385 software developers and data experts.

factorials

hsn
237 100+
hello everyone in my first programming subject our Dr. told us to find the factorial of n where n<10.
after that i tired to get the factorial of bigger number like 50 or 100
it doesn't work it give worng anser all the time. you know because the output will be a huge number (VERY HUGE).
what should i do to find the factorial of 100.
is there any special technique i should use or what.

regards
hsn
Feb 24 '08 #1
2 1239
If I remember it correctly isn't the factorial of 100 written as 100!
And isn't that basicly 1*2*3*...*98*99*100?

So basicly you want to do it while your counter is smaller or equals n.
And your counter starts at 1 and every loop it needs to be incremented by one.

If you can't find the solution by coding then try writing down what you want to achieve ;)
Feb 24 '08 #2
Banfa
9,065 Expert Mod 8TB
The problem, that you seem to be aware of is that a 32 bit integer is not big enough to hold the result, in fact a 32 bit integer can hold up to 12! but not 13!.

There are a number of possible solutions a bigger integer is the most obvious thought, many systems have 64 bit integer today. Unfortunately that will not help, a 64 bit integer can hold up to 20!.

You could also use doubles to get an approximation to the factorial, but the result will not be accurate.

What you really need is a much much larger integer. The way to do this in C++ is to create a class that acts as a much larger integer using multiple integers to hold digits in your large integer.

You could write this from scratch, but you can also find implementations on the web already, I know GNU has a large integer class.
Feb 24 '08 #3

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

Similar topics

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...
4
by: lothario | last post by:
this question i cant answer it maybe you will laugh but i cant the question is: 1/1!+2/2!+3/3!+4/4!+5/5!+6/6! i want the answer in visual basic language please i am waiting for reply
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>...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?

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.