它可以在以下查詢的幫助下創建 –
mysql> Delimiter // mysql> CREATE PROCEDURE fact(IN x INT) -> BEGIN -> DECLARE result INT; -> DECLARE i INT; -> SET result = 1; -> SET i = 1; -> WHILE i <= x DO -> SET result = result * i; -> SET i = i + 1; -> END WHILE; -> SELECT x AS Number, result as Factorial; -> END// Query OK, 0 rows affected (0.17 sec)
登錄后復制
現在,當通過傳遞我們想要獲取階乘作為參數的值來調用此過程時 –
mysql> Delimiter ; mysql> CALL Fact(5); +--------+-----------+ | Number | Factorial | +--------+-----------+ | 5 | 120 | +--------+-----------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec) mysql> CALL Fact(6); +--------+-----------+ | Number | Factorial | +--------+-----------+ | 6 | 720 | +--------+-----------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)
登錄后復制
以上就是創建一個程序來找出數字的階乘?的詳細內容,更多請關注www.92cms.cn其它相關文章!