4个回答
展开全部
首先声明 我是复制党...
答案一:Private Sub Form_click()
Dim a(1 To 3000) As Integer, n As Integer
Dim wei As Integer, jinwei As Integer, w As Integer
n = InputBox("请输入一个小于1000的正整数以计算其阶乘", "输入框")
wei = 1
For i = 1 To 3000
a(i) = 1
Next
For i = 2 To n
jinwei = 0
For j = 1 To wei
w = a(j) * i + jinwei
a(j) = w Mod 10
jinwei = Int(w / 10)
Next j
Do While jinwei > 0
wei = wei + 1
a(wei) = jinwei Mod 10
jinwei = jinwei \ 10
Loop
Next i
Print n; "的阶乘共"; wei; "位"
nn = wei - 30
Do
For i = wei To nn Step -1
Print a(i);
Next
Print
wei = nn - 1
nn = wei - 30
Loop While nn > 1
For i = wei To 1 Step -1
Print a(i);
Next
End Sub
参考 http://zhidao.baidu.com/question/28982267.html?fr=ala1
答案二:#include <stdio.h>
int main()
{
int n;
int a[9000]; //确保保存最终运算结果的数组足够大
int digit = 1; //位数
int temp; //阶乘的任一元素与临时结果的某位的乘积结果
int i,j,carry; //进位
printf("please in put n:\n");
scanf("%d",&n);
a[0] = 1; //将结果先初始化为1
for(i = 2; i <= n; i++)
{ //开始阶乘,阶乘元素从2开始依次"登场"
//按最基本的乘法运算思想来考虑,将临时结果的每位与阶乘元素相乘
for( j = 1, carry = 0; j <= digit; j++)
{ //carry:进位
temp = a[j-1] * i + carry; //相应阶乘中的一项与当前所得临时结果的某位//相乘(加上进位)
a[j-1] = temp % 10; //更新临时结果的位上信息
carry = temp / 10; //看是否有进位
}
while(carry)
{ //如果有进位
a[++digit-1] = carry % 10; //新加一位,添加信息。位数增1
carry = carry/10; //看还能不能进位
}
}
printf("n ! = "); //显示结果
for(j = digit; j >=1;j--)
{
printf("%d",a[j-1]);
}
printf("\n");
return 0;
}
这个是比较通用的算法,你可以验证其正确性.
(EXCEL 有阶乘的功能,你随便输入一个数,用单元格写=fact(100),就可以知道值是多少.)
答案一:Private Sub Form_click()
Dim a(1 To 3000) As Integer, n As Integer
Dim wei As Integer, jinwei As Integer, w As Integer
n = InputBox("请输入一个小于1000的正整数以计算其阶乘", "输入框")
wei = 1
For i = 1 To 3000
a(i) = 1
Next
For i = 2 To n
jinwei = 0
For j = 1 To wei
w = a(j) * i + jinwei
a(j) = w Mod 10
jinwei = Int(w / 10)
Next j
Do While jinwei > 0
wei = wei + 1
a(wei) = jinwei Mod 10
jinwei = jinwei \ 10
Loop
Next i
Print n; "的阶乘共"; wei; "位"
nn = wei - 30
Do
For i = wei To nn Step -1
Print a(i);
Next
wei = nn - 1
nn = wei - 30
Loop While nn > 1
For i = wei To 1 Step -1
Print a(i);
Next
End Sub
参考 http://zhidao.baidu.com/question/28982267.html?fr=ala1
答案二:#include <stdio.h>
int main()
{
int n;
int a[9000]; //确保保存最终运算结果的数组足够大
int digit = 1; //位数
int temp; //阶乘的任一元素与临时结果的某位的乘积结果
int i,j,carry; //进位
printf("please in put n:\n");
scanf("%d",&n);
a[0] = 1; //将结果先初始化为1
for(i = 2; i <= n; i++)
{ //开始阶乘,阶乘元素从2开始依次"登场"
//按最基本的乘法运算思想来考虑,将临时结果的每位与阶乘元素相乘
for( j = 1, carry = 0; j <= digit; j++)
{ //carry:进位
temp = a[j-1] * i + carry; //相应阶乘中的一项与当前所得临时结果的某位//相乘(加上进位)
a[j-1] = temp % 10; //更新临时结果的位上信息
carry = temp / 10; //看是否有进位
}
while(carry)
{ //如果有进位
a[++digit-1] = carry % 10; //新加一位,添加信息。位数增1
carry = carry/10; //看还能不能进位
}
}
printf("n ! = "); //显示结果
for(j = digit; j >=1;j--)
{
printf("%d",a[j-1]);
}
printf("\n");
return 0;
}
这个是比较通用的算法,你可以验证其正确性.
(EXCEL 有阶乘的功能,你随便输入一个数,用单元格写=fact(100),就可以知道值是多少.)
展开全部
100!等于
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
有158位数,尾数是0
问的很好下次不要再问了
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
有158位数,尾数是0
问的很好下次不要再问了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
=9.3326215443944 * 10^157
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
9.332621544394417e+157
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询