Home > Backend Development > C++ > body text

Print a long integer in C using putchar() function

王林
Release: 2023-08-28 08:21:05
forward
1575 people have browsed it

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);
}
Copy after login

Output

84571
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!