hi guys! plz help with the code in C which can calculate the fectorial of 500.

Recommended Answers

All 6 Replies

hi guys! plz help with the code in C which can calculate the fectorial of 500.

Could we see what you have so far.

>plz help with the code in C which can calculate the fectorial of 500.
The first thing you need to do is figure out how to do arbitrary precision arithmetic. 500! is a rather large number, after all:

1220136825991110068701238785423046926253574342803192842192413588385845373153881997605496447502203281863013616477148203584163378722078177200480785205159329285477907571939330603772960859086270429174547882424912726344305670173270769461062802310452644218878789465754777149863494367781037644274033827365397471386477878495438489595537537990423241061271326984327745715546309977202781014561081188373709531016356324432987029563896628911658974769572087926928871281780070265174507768410719624390394322536422605234945850129918571501248706961568141625359056693423813008856249246891564126775654481886506593847951775360894005745238940335798476363944905313062323749066445048824665075946735862074637925184200459369692981022263971952597190945217823331756934581508552332820762820023402626907898342451712006207714640979456116127629145951237229913340169552363850942885592018727433795173014586357570828355780158735432768888680120399882384702151467605445407663535984174430480128938313896881639487469658817504506926365338175055478128640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Last I checked, that value exceeds the range of all the built-in types by a smidge or two.

This is a good library. Try inputting 500!
in their sample program and see what you get.


P.S : its factorial and not fectorial

It can be done using strings though. But I've not thought about it yet. The nature of this problem is similar to adding two 50 digit decimal numbers which has to done by strings

>It can be done using strings though.
Yes, it can. In fact, I'd say that's a starting point for the concept of an arbitrary length arithmetic library.

>But I've not thought about it yet.
The simplest way, at least conceptually, is to have strings of digits and then process them exactly as you would on paper using grade school arithmetic. It's not especially difficult, but for large numbers this naive solution can be very inefficient.

another feckless attempt to steal teh fectorial codez.

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.