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
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
printf("%d\n",25*24*23*21) ;
Sorry, that should have been
26*25*24*23
26*25*24*23
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> 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)! ??
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)! ??
358800
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.