Written in PHP: Output odd numbers within 100

王林
Release: 2024-03-09 22:46:02
Original
516 people have browsed it

Written in PHP: Output odd numbers within 100

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 . " "; // 输出奇数
    }
}
?>
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!