-1 php
<?php
$all = array();
enter code here
for($i = 1 ; $i <= 100 ; $i++){
$ric=sqrt($i);
if(is_int($ric) == true){
$all[] = $i;
}
}
$max = max($all);
$min = min($all);
echo "MIN=".$min."<br>";
echo "MAX=".$max;
Run Code Online (Sandbox Code Playgroud)
你好,我改变了我的代码,而不是if((int)$ric - $ric == 0)我写这个,if(is_int($ric) == true)但它让我错了。有什么问题?请帮帮我。
将$i满足条件的所有元素放入一个数组中。然后,您可以使用min()和max()函数来获取最小值和最大值。
<?php
$all_i = [];
for($i = 1 ; $i <= 100 ; $i++){
$ric=sqrt($i);
if((int)$ric - $ric == 0){
$all_i[] = $i;
}
}
$max_i = max($all_i);
$min_i = min($all_i);
echo "Min = $min_i<br>Max = $max_i<br>";
echo "All = " . implode(", ", $all_i) . "<br>";
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
58 次 |
| 最近记录: |