Print an integer using only putchar. Try doing it without
using extra storage.

Answers were Sorted based on User's Feedback

Print an integer using only putchar. Try doing it without using extra storage...

Answer / raghuram

void putlong(unsigned long x)
{ if (x > 10) putlong(x / 10);
putchar(x % 10+'0');
long int a;
printf("enter long integer:");
return 0;


Is This Answer Correct ?    22 Yes 5 No

Print an integer using only putchar. Try doing it without using extra storage...

Answer / cmos

This can be done by recursion.
Since the number of recursive calls is not significant, it does not affect the performance much

printnumber(int i)
if(i == 0)
putchar(’0′ + i%10);

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More C Code Interview Questions

void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); printf("%u \n",gotit=--giveit); }

1 Answers  

To reverse an entire text file into another text file.... get d file names in cmd line

0 Answers   Subex,

main() { register int a=2; printf("Address of a = %d",&a); printf("Value of a = %d",a); }

3 Answers  

To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates.

19 Answers   Amazon, Syncfusion, Vector, Microsoft, Synergy, BITS,

How we will connect multiple client ? (without using fork,thread)

3 Answers   TelDNA,

void main() { int *mptr, *cptr; mptr = (int*)malloc(sizeof(int)); printf(“%d”,*mptr); int *cptr = (int*)calloc(sizeof(int),1); printf(“%d”,*cptr); }

1 Answers  

#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }

1 Answers  

write a c-program to find gcd using recursive functions

5 Answers   HTC, Infotech,

to remove the repeated cahracter from the given caracter array. i.e.., if the input is SSAD output should of SAD

6 Answers   Synergy,

Question: We would like to design and implement a programming solution to the reader-writer problem using semaphores in C language under UNIX. We assume that we have three readers and two writers processes that would run concurrently. A writer is to update (write) into one memory location (let’s say a variable of type integer named temp initialized to 0). In the other hand, a reader is to read the content of temp and display its content on the screen in a formatted output. One writer can access the shared data exclusively without the presence of other writer or any reader, whereas, a reader may access the shared memory for reading with the presence of other readers (but not writers).

1 Answers  

There is a lucky draw held every day. if there is a winning number eg 1876,then all possible numbers like 1867,1687,1768 etc are the numbers that match irrespective of the position of the digit. Thus all these numbers qualify fr the lucky draw prize Assume there is no zero digit in any numbers. write a program to show all the possible winning numbers if a "winning number"is passed as an arguments to the function.

1 Answers   Nagarro,

Is the following code legal? struct a { int x; struct a b; }

1 Answers