用数据库编程计算10的阶乘

如题所述

S=1FOR J= 1 TO 10S=S*JNEXT? S【问题中已经说是1 到10 的阶乘,故直接到10 答案 3628800】
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-05-23
CLEAR
INPUT "请输入N的值:" TO N
S=1
I=1
DO WHILE I<=N
S=S*I
I=I+1
ENDDO
?ALLTRIM(STR(N))+"的除是:",S本回答被网友采纳
第2个回答  2013-07-21
declare @t int
set @t = 10 --计算的阶乘
set nocount on
declare @ta table(id int identity(1,1) primary key,col bigint)
insert @ta(col) select 1

declare @n int,@i int,@c bigint,@len int,@tmp bigint

set @len=1;
set @n = @t

while (@n >=1)
begin
select @c = 0 ,@i = 1
select @tmp = col from @ta where id = @i
while (@i <= @len)
begin
set @tmp = @tmp*@n+@c
set @c = @tmp / 10000000000000
set @tmp = @tmp % 10000000000000
update @ta
set col = @tmp where id = @i;

set @i = @i + 1
if not exists(select 1 from @ta where id = @i)
insert @ta (col) select 0
select @tmp = col from @ta where id = @i
end
update @ta
set col = @c where id = @i;
if (@c>0)
set @len = @len + 1
set @n = @n - 1
end
第3个回答  2013-07-21
declare @i int ,@num int, @jc int set @num = 10 --10!
set @i =1
set @jc =1 while @i<=@num
begin
set @jc = @jc *@i
set @i = @i+1
end print @jc

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网