仅使用 putchar() 在 C 中打印 long int
在这里我们将看到如何使用putchar()C中的函数打印longint值。我们可以使用printf()C轻松打印一些变量的值,但这里的限制是,我们不能使用除之外的任何其他函数putchar()。
众所周知,putchar()用于仅打印字符。我们可以使用这个函数来打印数字的每一位。当传递一个数值时,我们必须在它上面加上字符“0”才能得到ASCII形式。让我们看看代码以获得更好的想法。
示例
#include输出结果void print_long(long value) { if(value != 0) { print_long(value/10); putchar((value%10) + '0'); } } main(void) { long a = 84571; print_long(a); }
84571