如何编写程序以找出任意数字的阶乘? [英] How to write a program to find out the factorial of any number?

查看:73
本文介绍了如何编写程序以找出任意数字的阶乘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个程序以找出任意数量的阶乘.:confused:

Write a program to find out the factorial of any number.:confused:

推荐答案

艰巨的任务,即使不是不可能!我不喜欢尝试写这个.计算机的一个问题是它们是有限界的,而正整数的集合不是...

干杯,



PS对CPallini的评论:我可能认为我的阶乘仅针对整数和零进行了定义,这可能是错误的.如果您有任何经验,我会对纯数学或应用数学中对非积分阶乘的任何引用都感兴趣(尽管可能不会理解).

PPS:当然,现在正在搜索阶乘非整数",我已经足以破坏我的周末!
Tough job, if not impossible! I don''t fancy trying to write this. One problem with computers are they''re finitely bounded and the set of positive integers isn''t...

Cheers,

Ash

PS to CPallini''s comment: I may be wrong by I thought factorials were only defined for integers and zero. I''d be interested in (although probably wouldn''t understand) any references to non-integral factorials in either pure or applied maths if you''ve got any to hand.

PPS: And of course now doing a search for "factorial non-integer" I''ve got more than enough to ruin my weekend!


获取自然数的合理子集(请参阅 Aescleal 的警告),该任务几乎是微不足道的,只是一个迭代(周围有示例代码可用...).
请开始编码!
:)
For a reasonable subset of the natural numbers (see Aescleal''s caveat), the task is almost trivial, just an iteration (and there is sample code available all around you...).
Please, start coding!
:)


计算阶乘的代码很简单,因此您可以自己编写;唯一的问题可能是您要处理的数字大小.
如果使用编译器提供的本机类型,则有以下限制:


  • 一个unsigned int(大小为32位)最多可以容纳12个!
  • 一个unsigned __int64(大小为64位)最多可以容纳20个!
The code to compute the factorial is trivial so you can write it by yourself; the only problem could be the size of numbers you want to deal with.
If you use the native types provided by your compiler, you have this limits:


  • an unsigned int (32 bit in size) can hold at most 12!
  • an unsigned __int64 (64 bit in size) can hold at most 20!


这篇关于如何编写程序以找出任意数字的阶乘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆