ALLInterview.com :: Home Page            
 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                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2254)
 C++ interview questions  C++ Interview Questions (1111)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (646)
Question
Write a program in c to input a 5 digit number and print it
in words.
 Question Submitted By :: C
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
#include<stdio.h>
#include<conio.h>

char a[10][12]={"one","two","three","four","five","six","seven","eight","nine"};
char b[10][15]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","ninteen"};
char tens[10][15]={"twenty","thirty","fourtey","fiftey","sixty","seventy","eighty","ninty"};

int check(long int num)
{
if(num>10000000)return 5;
if(num>100000)return 4;
else if(num>1000)return 1;
else if(num>100)return 2;
else if(num>10)return 3;
else

return 0;
}

void prnt(long int num,char *s)
{ int n;
if(num<10)
{
printf(" %s %s",a[num-1],s);

}
else if(num>10 && num<20)
{
printf(" %s %s",b[(num-10)-1],s);
}
else if(num>20)
{
printf(" %s ",tens[(num-20)/10]);

n=num%10;
printf(" %s %s",a[n-1],s);
}

}

void main()
{
long int num,n;
int ch=1;

printf("enter no\n");
scanf("%ld",&num);

while( ch!=0)
{

ch=check(num);

// if(ch==0)
// goto l1;

switch(ch)
{
case 1:
n=num/1000;
prnt(n," thousand");
num=num-n*1000;
break;
case 2:
n=num/100;
prnt(n," hundred ");
num=num-n*100;
break;
case 3:
printf(" %s",tens[(num-20)/10]);
num=num%10;
break;
case 4:
n=num/100000;
prnt(n,"lacks");
num=num-n*100000;
break;
case 5:
n=num/10000000;
prnt(n,"crores");
num=num-n*10000000;
break;

}

}
printf(" %s",a[num-1]);
getch();
}
 
Is This Answer Correct ?    95 Yes 21 No
Sunil
 
Answer
# 2
/*write a program to accept any number up to five digits and
print that in words(without using array). for example- 1265=
one two six five*/
#include<stdio.h>
#include<stdlib.h>
main()
{
int x,mod, rev=0;
printf("enter number(up to five digits)");
scanf("%d", &x);
if(x>99999)
{
printf("invalid number");
exit(0);
}
while(x>0)
{
mod=x%10;
rev=rev*10+mod;
x=x/10;
}
while(rev>0)
{
mod=rev%10;
switch(mod)
{
case 1:
printf("one ");
break;
case 2:
printf("two ");
break;
case 3:
printf("three ");
break;
case 4:
printf("four ");
break;
case 5:
printf("five ");
break;
case 6:
printf("six " );
break;
case 7:
printf("seven ");
break;
case 8:
printf("eight ");
break;
case 9:
printf("nine ");
break;
case 0:
printf("zero ");
break;
}
rev=rev/10;
}
printf("\n");
}
 
Is This Answer Correct ?    16 Yes 8 No
Mayank
 
 
 
Answer
# 3
i dont have answer i'm actually asking question..

What if we want to print upto nth term??

in a very first post
"


#include<stdioi.h>
void main()
{
int n,count=0,a[20];
scanf("%d",&n);
for(i=0;n>0;i++)
{
a[i]=n%10;
n=n/10;
count++;
}
for(i=0;i<count;i++)
{
switch(a[i])
{
case 1:
printf("one");
break;
case 2:
printf("two");
break;
"

he explicitly doing this using switch case.
 
Is This Answer Correct ?    5 Yes 2 No
Siddiqui_1985
 
Answer
# 4
# include <stdio.h>
int main ()
{
int n,temp,t,s=0,i,ctr=0;
char a[10][10] = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine"};
printf ("Enter the number:\n");
scanf ("%d", &n);
//printf ("The given num in word = %s\n", a[n]);
t=n;
while(n>0)
{
ctr++;
n=n/10;
}
while(t>0)
{
temp=t%10;
s=10*s+temp;
t=t/10;
}

for(i=0;i<ctr;i++)
{
printf("%s",a[s%10]);
s=s/10;
}
}
 
Is This Answer Correct ?    15 Yes 14 No
Rakesh.bit
 
Answer
# 5
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
printf("Enter the no");
scanf("%d",&no);
switch(no)
{
case 1:
printf("One");
break;
case 2:
printf("Two");
break;
case 3:
printf("Three");
break;
case 4:
printf("Four");
break;
case 5:
printf("Five");
break;
case 6:
printf("Six");
break;
case 7:
printf("Seven");
break;
case 8:
printf("Eight");
break;
case 9:
printf("Nine");
break;
default:
printf("You entered Wrong input");
break;
}
}
 
Is This Answer Correct ?    0 Yes 0 No
Sachin Patel
 
Answer
# 6
in ans #8,if we,even,reverse the number we can'nt get right
ans in all cases.for example if we enter 1000 than it will
be reversed 0001 and computer will [rint 1 only
 
Is This Answer Correct ?    0 Yes 1 No
Vaibhav Dubey
 
Answer
# 7
the program u wrote is wrong because it prints in reverse
means if u gave 12345 the output will be five four three
two one like this
for getting correct output the given number would be
reversed and we write code for that reversed number.
 
Is This Answer Correct ?    22 Yes 28 No
Manoj Kumar
 
Answer
# 8
OK HERE they are asking for 5 digits , but if somewhere
they ask for 'n' digit numbers , then that a[6] wont work
there , Whenever u do a program u will also think of the
worst cases then only we must develop a program...... in all
situations ur program should work!!!!!!!! that's speaks !!

thank u
 
Is This Answer Correct ?    23 Yes 34 No
Vignesh1988i
 
Answer
# 9
# include <stdio.h>
int main ()
{
int n;
char a[10][10] = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine"};
printf ("Enter the number:\n");
scanf ("%d", &n);
printf ("The given num in word = %s\n", a[n]);
}
 
Is This Answer Correct ?    22 Yes 34 No
Swathi
 
Answer
# 10
they directly asks for 5 digit naaa

so read that into a c[6] like that

and print c[0] thousand like that..........
 
Is This Answer Correct ?    30 Yes 80 No
Prawin62
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
class foo { public: static int func(const char*& p) const; }; This is illegal, why? Google 8
program for swapping two strings by using pointers in c language   1
void main() { int s[4][2]={ {1234,56},{1212,33},{1434,80},{1312,78} }; int (*p)[2]; int i,j,*pint; for(i=0;i<=3;i++) { p=&s[i]; pint=p; printf("\n"); for(j=0;j<=1;j++) printf("%d",*(pint+j)); } } while running this program it shows a warning-suspicious pointer conversion ie pint=p; my que is why should we assign the value of p to pint again.why cant we use it directly as *(p+j)..but if i use like tat the o/p is garbage value..   1
what is op? for(c=0;c=1000;c++) printf("%c",c); Trigent 20
yogesh patil in dell DELL 3
program for validity of triangle from 3 side   7
write a program wch produces its own source code aas its output? IonIdea 1
what are the stoge class in C and tel the scope and life time of it? Tech-Mahindra 2
An interactive c program to read basic salary of 15 persons. each person gets 25% of basic as HRA, 15%of basic as conveyance allowances, 10%of basic as entertainment allowances.The total salary is calculated by adding basic+HRA+CA+EA.Calculate how many out of 15 get salary above 10,000.Rs also print the salary of each employee   2
what is diff between localstatic and globalstatis variable possible 2 use in another file...? HCL 2
which do you prefer C or Pascal?   1
How does C++ help with the tradeoff of safety vs. usability?   1
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com