ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
Given only putchar (no sprintf, itoa, etc.) write a routine
putlong that prints out an unsigned long in decimal.
 Question Submitted By :: =-PKG-=
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.
Answer
# 1
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 ?    3 Yes 0 No
Prateek Caire
 
  Re: Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.
Answer
# 2
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 ?    1 Yes 4 No
Rakesh
 
 
 
  Re: Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.
Answer
# 3
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 0 No
Meibella
 
  Re: Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.
Answer
# 4
#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 ?    3 Yes 0 No
Raghuram.A
 
  Re: Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.
Answer
# 5
#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 ?    0 Yes 0 No
Suraj Gupta
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
main() { printf("\nab"); printf("\bsi"); printf("\rha"); }  1
main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); }  1
main() { int i; i = abc(); printf("%d",i); } abc() { _AX = 1000; }  1
main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcpy(a,b)); } a. “Hello” b. “Hello World” c. “HelloWorld” d. None of the above HCL1
main() { struct date; struct student { char name[30]; struct date dob; }stud; struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year); }  1
void main () { int x = 10; printf ("x = %d, y = %d", x,--x++); } a. 10, 10 b. 10, 9 c. 10, 11 d. none of the above HCL1
main() { char string[]="Hello World"; display(string); } void display(char *string) { printf("%s",string); }  1
#include<conio.h> main() { int x,y=2,z,a; if(x=y%2) z=2; a=2; printf("%d %d ",z,x); }  1
#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above HCL1
main() { char * strA; char * strB = I am OK; memcpy( strA, strB, 6); } a. Runtime error. b. I am OK c. Compile error d. I am O HCL2
main() { float i=1.5; switch(i) { case 1: printf("1"); case 2: printf("2"); default : printf("0"); } }  1
main() { char *cptr,c; void *vptr,v; c=10; v=0; cptr=&c; vptr=&v; printf("%c%v",c,v); }  1
int DIM(int array[]) { return sizeof(array)/sizeof(int ); } main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr)); }  1
main() { extern out; printf("%d", out); } int out=100;  1
Give a one-line C expression to test whether a number is a power of 2. Microsoft8
Write a function to find the depth of a binary tree. Adobe8
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it. Wipro2
void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }  1
char inputString[100] = {0}; To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString, sizeof(inputString), fp)  1
What are segment and offset addresses? Infosys1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com