SQL SERVER 求阶乘之和

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/baidu_32731497/article/details/51588311

求阶乘之和:

CREATE PROCEDURE proc_jc
@num INT
AS
BEGIN
  DECLARE @cj INT,@sum INT,@i INT;
  SELECT @cj=1,@sum=0,@i=1;
  WHILE @i<=@num
    BEGIN
       SET @cj=@cj*@i;
       SET @sum=@sum+@cj;
       SET @i=@i+1;
    END
   PRINT CAST(@num AS VARCHAR(30))+'的阶乘之和是'+CAST(@sum AS VARCHAR(50));
END

执行存储过程:

EXEC proc_jc 3;

删除存储过程:

DROP PROCEDURE proc_jc;

没有更多推荐了,返回首页