给定一个数字,您的任务是使用pl/sql打印该数字的阶乘。
null
例如:
Input : 5 Output : 120
说明: 5! = 5 * 4 * 3 * 2 * 1 = 120
Input : 4 Output : 24
pl/sql块的基本结构
declare -- declare all the variables begin -- for start block -- make a program here end -- for end block
pl/sql中数字的阶乘程序如下:
declare -- it gives the final answer after computation fac number :=1; -- given number n -- taking input from user n number := &1; -- start block begin -- start while loop while n > 0 loop -- multiple with n and decrease n's value fac:=n*fac; n:=n-1; end loop; -- end loop -- print result of fac dbms_output.put_line(fac); -- end the begin block end ; |
输出: (如果输入为5)
120
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END