How to print numbers with leading zeros in C

2 Answers

0 votes
#include <stdio.h>

int main(void) {
    int a = 23, b = -8;

    printf("%+.5i %+.5i\n", a, b);
    printf("%.5i %.5i\n", a, b);

    return(0);
}





/*
run:

+00023 -00008
00023 -00008

*/

 



answered May 4, 2021 by avibootz
0 votes
#include <stdio.h>

int main(void) {
    int a = 23, b = -8;

    printf("%+05i %+05i\n", a, b);
    printf("%05i %05i\n", a, b);

    return(0);
}





/*
run:

+0023 -0008
00023 -0008

*/

 



answered May 4, 2021 by avibootz

Related questions

...