Given only putchar (no sprintf, itoa, etc.) write a routine
putlong that prints out an unsigned long in decimal.




Answers were Sorted based on User's Feedback



Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned lon..

Answer / raghuram.a

#include <stdio.h>
#include<conio.h>
void putlong(unsigned long x)
{
if (x>=10)
{
putlong(x/10);
}
putchar(x%10+48);
}
main()
{
unsigned long a;
clrscr();
printf("enter long integer:");
scanf("%ld",&a);
putlong(a);
getch();
return 0;

}

Is This Answer Correct ?    12 Yes 0 No

Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned lon..

Answer / prateek caire

void print(unsigned n)
{
static c = 0;
if( n < 10)
{
putchar(n + 48);
return;
}
int m = n%10;
print(n/10);
if(++c%3 == 0) putchar(',');
putchar(48 + m);
}

Is This Answer Correct ?    7 Yes 2 No

Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned lon..

Answer / suraj gupta

#include<stdio.h>
#include<string.h>
void printInt(unsigned long x){
int div=1;
if (x > 10){
div=x/10;
printInt(div);
}
//putchar(x % 10+'0');Both will work fine
putchar(x % 10+48);
}
int main(){
long int a;
printf(" Enter integer value : ");
scanf("%d",&a);
printf("\n");
printInt(a);
return 0;
}

Is This Answer Correct ?    1 Yes 1 No




Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned lon..

Answer / sanjay

#include<stdio.h>
#include<conio.h>

int main()
{
unsigned long abc=234455787; int div1;
div1=print_int(abc);
getch();
}


int print_int(long val)
{ int div=1; char c;
if (val>=10)
{
div=print_int(val/10);
}
putchar(val%10+48);
return (1);
}

Is This Answer Correct ?    0 Yes 0 No

Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned lon..

Answer / meibella

void putLong(unsigned int x, unsigned int *a, int *j)
{
unsigned int temp = x/10;
unsigned int remainder = x%10;
a[(*j)++] = remainder;
if (temp < 1)
return ;
else
putLong(temp,a,j);


}
int main()
{
unsigned int * a = new unsigned int[12] ;
int j =0;
putLong(1735648,a,&j);
for (int i = j-1; i>=0; i--)
{
putchar(a[i]+48);
}
return 0;
}

Is This Answer Correct ?    0 Yes 2 No

Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned lon..

Answer / rakesh

void main()
{
unsigned long n;
int i;
void putlong(unsigned long);
cout<<"\nEnter the number::";
cin>>n;
putlong(n);
}

void putlong(unsigned long n)
{
if(n==0)
return;
print(n/10);
putchar((n%10) + 48);

}

Is This Answer Correct ?    2 Yes 10 No

Post New Answer



More C Code Interview Questions

const int perplexed = 2; #define perplexed 3 main() { #ifdef perplexed #undef perplexed #define perplexed 4 #endif printf("%d",perplexed); } a. 0 b. 2 c. 4 d. none of the above

1 Answers   HCL, emc2,


programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h

1 Answers  


Write a procedure to implement highlight as a blinking operation

2 Answers  


Derive expression for converting RGB color parameters to HSV values

1 Answers  


String copy logic in one line.

11 Answers   Microsoft, NetApp,






main() { char *p = "hello world"; p[0] = 'H'; printf("%s", p); } a. Runtime error. b. “Hello world” c. Compile error d. “hello world”

5 Answers   HCL,


A program that will create a movie seat reservation. The program will display the summary seats and its status. The user will be ask what seat no. to be reserved, then it will go back again to the summary to display the updated seat status. If the seat no. is already reserved then it will prompt an error message. And also if the input seat no is out of range then it will also prompt an error message. The program is continuously running. Termination of the program will depends on how the programmer will apply. Sample output: Movie Seats Reservation Summary of Seats: Seat 1: Available Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 1 Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 6 The Seat no. is out of range! Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 1 The Seat no. is already reserved! Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 0 GoodBye... Thank You!!!

0 Answers  


plz send me all data structure related programs

2 Answers  


could you please send the program code for multiplying sparse matrix in c????

0 Answers  


main() { char *p = “ayqm”; printf(“%c”,++*(p++)); }

29 Answers   IBM, TCS, Wipro, UGC NET,


why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

0 Answers  


prog. to produce 1 2 3 4 5 6 7 8 9 10

4 Answers   TCS,






Categories