Hello,
I've just wrote a small program to calculate the factorial of a given number. When i give a small number everything is ok but when i want t calculate the factorial of a biger number, like 53!, I get a wrong answer.
I thing that the problec is the type of the type I use(unsigned long int).
Can anyone please helpmewith that;
em_i
9
Newbie Poster
Recommended Answers
Jump to Postunfortunately there is really nothing you can do about it except to use a 64-bit integer, such as long long or _int64. What you are experiencing is data overflow -- integers can only hold a finite number of digits. The file limits.h contains macros that are the maximum values for …
Jump to Postif you are interested in only an approximate value, you could use a type like double for computing the result. for example, a long double can hold very large values, but precision is limited (on my compiler, the mantissa is accurate upto 15 decimal digits).
#include <limits> …
All 5 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
vijayan121
1,152
Posting Virtuoso
SpS
commented:
Nicely Presented
+3
em_i
9
Newbie Poster
vijayan121
1,152
Posting Virtuoso
iamthwee
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.