Of course, the following is a code example written in PHP, which can output all odd numbers within 100:
<?php // 循环输出 1 到 100 的奇数 for ($i = 1; $i <= 100; $i++) { if ($i % 2 != 0) { echo $i . " "; // 输出奇数 } } ?>
This code traverses all the numbers from 1 to 100 through a for loop numbers, and then determine whether each number is an odd number (that is, the remainder divided by 2 is not 0), and if it is an odd number, output it. Finally, the following content will be output:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
This achieves the function of outputting all odd numbers within 100.
The above is the detailed content of Written in PHP: Output odd numbers within 100. For more information, please follow other related articles on the PHP Chinese website!