c program to calculate factorial of large numbers
This is my solution to calculate the factorial of large numbers upto 3300 and can be extended depending on your system memory.To increase range change constant ARRAY_SIZE:pleased::pleased:
Code: cpp Code:
#include <stdio.h> 
Re: c program to calculate factorial of large numbers
thank you man
i could really use that 
Re: c program to calculate factorial of large numbers
thank you man
i could really use that 
Re: c program to calculate factorial of large numbers
Quote:

Re: c program to calculate factorial of large numbers
i am trying to learn C++,but to be honest , don't understand a line there.
that's not good at all (wish i could know C++) and i hate copying, i really do, even in real life. 
Re: c program to calculate factorial of large numbers
Quote:
you must learn c before learning c++ ,actually above code is in c not in c++.... can you differentiate between c and c++ ? srry but i think you can't 
Re: c program to calculate factorial of large numbers
Code:
#include <stdio.h> in the whooping time of 22.218 seconds, on my laptop which is a 4 year old HP. There is actually no limit whatsoever to what factorial you can calculate with this code, as long as you add to N the required length. I advise that if you start seeing zeroes at the end, you should make your N smaller. It will take less time. A standard and not a scary example of the power of this code: 10!  N=7, 3.14 secs... 100!  N=158, 1.906 secs... 1000!  N=2568, 2.671 secs... As you can see, it's more powerful as the facts go up... Have fun. And sorry for the over enthusiasm, it's the first time I publish code online...:shy: 
Re: c program to calculate factorial of large numbers
sorry if i am being rude but the code you have posted is less practical to be used in real life problems
first of all to print out the correct value of a factorial you must know the number of digits in the result in advance so that you can set the value of N for eg if N=3 5!=021 if N=4 5!=0120 (wrong answer) tell me how the user will be able to know the number of digits in the result ? for eg if user wants to calculate 1331! ,from where he will get the value of N? again your code is printing the digits in a result in reverse order.that is also not cool if you want to use that result in another calculation. at last you said that your code is taking 22 secs to calculate 10000!.sorry if i am biased towards my code but my code is still taking less time ((my code ) 8 secs on my machine vs (your code) 20 secs on my machine ) to calculate 10000!. correct me if i am wrong thank you 
Re: c program to calculate factorial of large numbers
Well, you can surely use it in another calculation, because the array is still there,
it doesn't just print out the result and dissipates. Besides, I didn't say that my code was superior, I just said that it is more easily understandable to people who are not on a high level, which I myself wasn't the time I published the code. Now I am, but I can still relate to people who read your code and say "huh? I don't understand where it all goes..." cause that is what I felt. And when I ran your code (and I did, ofc) the results were quite similar. :) But the point is not the speed because it gives the result. :) And regarding the "if N=4 5!=0120 (wrong answer)" No, the answer it will give if N=4 is: 0210 which is correct if you read it from the right to the left. You are not supposed to KNOW the N, you print the result, then if you have zeroes at the beginning of the number, you make the N smaller, but you don't really have to. If you don't see zeroes, there is a risk that it's not all of the answer so you make the N bigger. I hope I was able to answer all of your questions,since this is my first time publishing code, I was never this excited about programming. :) 
Re: c program to calculate factorial of large numbers
Quote:
for n=4 5!===> a[0]=0,a[1]=2,a[2]=1,a[3]=0 surely you can't use this array in that way.you have to first reverse it and then you have to left shift the whole array to come up with the proper answer.This is just like adding another level of complexity to the code... 
All times are GMT +5.5. The time now is 14:36. 