printf fill with 0
#include <stdio.h>
int main() {
int num = 42;
printf("%04d", num);
return 0;
}
This code snippet uses the printf
function in C to print the value of the variable num
with leading zeros. The format specifier %04d
specifies that the number should be printed with a minimum width of 4 digits, padded with leading zeros if necessary.