Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
karthikeya Boyini

Here we will see how to print long int value using the putchar() function in C. We can easily print the value of some variables using printf() in C, but here the restriction is, we cannot use any other function except putchar().

As we know that the putchar() is used to print only characters. We can use this function to print each digit of the number. When one numeric value is passed, we have to add character ‘0’ with it to get the ASCII form. Let us see the code to get the better idea.

Example

#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);
}

Output

84571

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.