Display Number Sequences in C

Displaying number sequences is a simple way to practice for loops, step values and formatting. The first example prints 1 to 100 with a line break after every ten numbers.

Display 1 to 100 in Rows of 10 Top ↑

#include <stdio.h>

int main(void) {
    for (int i = 1; i <= 100; i++) {
        printf("%3d ", i);

        if (i % 10 == 0) {
            putchar('\n');
        }
    }

    return 0;
}

The integer remainder operator % is enough here; fmod() is for floating-point values.

Print Even Numbers Top ↑

#include <stdio.h>

int main(void) {
    for (int i = 2; i <= 10; i += 2) {
        printf("%d ", i);
    }

    putchar('\n');
    return 0;
}

Display Numbers with Leading Zeros Top ↑

#include <stdio.h>

int main(void) {
    for (int i = 1; i <= 10; i++) {
        printf("%03d\n", i);
    }

    return 0;
}

%03d requests a field width of 3 and fills unused leading positions with zeros.

Print Odd Numbers Top ↑

#include <stdio.h>

int main(void) {
    for (int i = 1; i <= 10; i += 2) {
        printf("%d ", i);
    }

    putchar('\n');
    return 0;
}

Print Numbers in Reverse Order Top ↑

#include <stdio.h>

int main(void) {
    for (int i = 10; i >= 1; i--) {
        printf("%d ", i);
    }

    putchar('\n');
    return 0;
}

Display Negative Numbers Top ↑

#include <stdio.h>

int main(void) {
    for (int i = -1; i >= -10; i--) {
        printf("%d ", i);
    }

    putchar('\n');
    return 0;
}

Continue with Fibonacci numbers or review the for loop.





plus2net.com






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer