voidprint_long(longvalue){ &a"/> voidprint_long(longvalue){ &a">

Home  >  Article  >  Backend Development  >  Print a long integer in C using putchar() function

Print a long integer in C using putchar() function

王林
王林forward
2023-08-28 08:21:051598browse

Print a long integer in C using putchar() function

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.

Example

#include <stdio.h>
void print_long(long value) {
   if(value != 0) {
      print_long(value/10);
      putchar((value%10) + &#39;0&#39;);
   }
}
main(void) {
   long a = 84571;
   print_long(a);
}

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete