Here we will see how to print long int value using putchar() function in C. We can easily print the value of some variable using printf() in C, but the limitation here is that we cannot use any other function except putchar().
As we all know, putchar() is only used to print characters. We can use this function to print each digit of a number. When passing a numeric value we have to add the character "0" to get the ASCII form. Let's take a look at the code to get a better idea.
#include <stdio.h> 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
The above is the detailed content of Print a long integer in C using putchar() function. For more information, please follow other related articles on the PHP Chinese website!