Home > Backend Development > C#.Net Tutorial > How to express the range of a number in c language

How to express the range of a number in c language

下次还敢
Release: 2024-04-29 18:51:15
Original
563 people have browsed it

In C language, the range operator ... is used to represent a range of numbers, which includes all integers within the range. For example, for (i = 10 ... 20) represents all integers from 10 to 20. Range operators can also be used with other data types, such as char and enumerations.

How to express the range of a number in c language

Representing a numerical range in C language

In C language, you can use the range operator. .. represents a range of numbers that includes all integers within the range. For example:

<code class="c">int i;
for (i = 10 ... 20) {
    // ...
}</code>
Copy after login

This range represents all integers from 10 to 20 (inclusive), that is, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.

The range operator can also be used with other data types, such as characters and enumerations:

<code class="c">char c;
for (c = 'a' ... 'z') {
    // ...
}</code>
Copy after login

This range represents from 'a' to 'z' (including 'a' and 'z' ) all characters.

Example

<code class="c">int main() {
    int i;

    // 10 到 20
    for (i = 10 ... 20) {
        printf("%d ", i);
    }

    printf("\n");

    // 'a' 到 'z'
    char c;
    for (c = 'a' ... 'z') {
        printf("%c ", c);
    }

    printf("\n");

    return 0;
}</code>
Copy after login

Output result:

<code>10 11 12 13 14 15 16 17 18 19 20 
a b c d e f g h i j k l m n o p q r s t u v w x y z </code>
Copy after login

The above is the detailed content of How to express the range of a number in c language. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template