打印0领先在C语言中? [英] Printing leading 0's in C?
本文介绍了打印0领先在C语言中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找到打印0领先的,如01001为一个zip code的好办法。而数字将被存储为1001,什么是做一个好办法?
我想用这两种情况下语句/要是再找出多少多少个数字是,然后将其与额外的0转换为字符数组用于打印的,但我不禁想到有可能是一个办法做到这与被躲避我的printf格式语法。
解决方案
的printf(%05D,邮编code);
I'm trying to find a good way to print leading 0's, such as 01001 for a zipcode. While the number would be stored as 1001, what is a good way to do it?
I thought of using either case statements/if then to figure out how many digits the number is and then convert it to an char array with extra 0's for printing but I can't help but think there may be a way to do this with the printf format syntax that is eluding me.
解决方案
printf("%05d", zipCode);
这篇关于打印0领先在C语言中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文