Link to home
Start Free TrialLog in
Avatar of akohan
akohan

asked on

scientific numbers in C++

Hello group,

In a calculation I'm counting which gives result in scientifice number due to using Factorial such
26!/(26-4)! and ...

What varaible can I use? do I need to use template in C++? or how about PHP/JavaScript if you want to implement it in Web (either one)

Your help will be appreciated greatly.

Regards,
Amit
Avatar of ozo
ozo
Flag of United States of America image

printf("%d\n",25*24*23*21);
Sorry, that should have been
26*25*24*23
ASKER CERTIFIED SOLUTION
Avatar of rstaveley
rstaveley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> What varaible can I use?

A normal 32bit int should be fine, assuming that you calculate it correctly. Do NOT try to store 26! in it ;) A 32bit int can't hold the result :) Calculate like ozo showed.


>> do I need to use template in C++?

I do not see why ? This is a simple calculation ... Or do you want to make your code generic to calculate x!/(x-y)! ??
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To be extra safe, you might want to check the input x and y values for overflow ... If the difference between them is too small, the result will not be correct.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial