How to left align an integer?

To left align an integer in C, you can use the format specifier %-d. Here’s an example:

#include <stdio.h>

int main() {
    int number = 42;
    printf("%-5d\n", number); // This will print the number left-aligned in a field of width 5
    return 0;
}

In this example, the integer 42 will be printed left-aligned, followed by spaces to fill the total width of 5 characters.

0 Comments

no data
Be the first to share your comment!