Home  >  Article  >  Database  >  SQL求小于1000的所有水仙花数

SQL求小于1000的所有水仙花数

WBOY
WBOYOriginal
2016-06-07 14:55:055329browse

水仙花数是一个n(=3)位数字的数, 它等于每个数字的n次幂之和. 例如, 153是一个水仙花数, 153=1+5+3. 编写程序, 求解小于1000的所有水仙花数. 无 DECLARE i INTSET i=10WHILE i1000BEGINIF POWER(floor(i/100),3)+POWER(floor(i/10)%10,3)+POWER(i%10,3)=iPRI

水仙花数是一个n(>=3)位数字的数, 它等于每个数字的n次幂之和. 例如, 153是一个水仙花数, 153=1³+5³+3³. 编写程序, 求解小于1000的所有水仙花数.
DECLARE i INT
SET i=10
WHILE i<1000
BEGIN
IF POWER(floor(i/100),3)+POWER(floor(i/10)%10,3)+POWER(i%10,3)=i
PRINT i
END
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn