PowerShell:计算三位整数(100~999)的水仙花数

计算三位整数(100~999)的水仙花数

[int]$a = 100

for($a = 100;$a -le 999;$a++){

     [string]$y = $a

     [string]$b = $y.Substring(0,1)

     [string]$c = $y.Substring(1,1)

     [string]$d = $y.Substring(2,1)

    [int]$e = $b*$b*$b + ($c*$c*$c + $d*$d*$d)

     if($a -eq $e){

     write-output(“{0}是一个水仙花” -f $e)

}else{

       continue

}

猜你喜欢

转载自blog.csdn.net/Littleliuing/article/details/106911227