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 (2265)
 C++ interview questions  C++ Interview Questions (1119)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (648)
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 ?    96 Yes 22 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 ?    18 Yes 9 No
Mayank
 
 
 
Answer
# 3
# 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 ?    16 Yes 14 No
Rakesh.bit
 
Answer
# 4
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 3 No
Siddiqui_1985
 
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 ?    2 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 ?    1 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 ?    23 Yes 28 No
Manoj Kumar
 
Answer
# 8
# 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 ?    23 Yes 34 No
Swathi
 
Answer
# 9
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 35 No
Vignesh1988i
 
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 81 No
Prawin62
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
i want to have a program to read a string and print the frequency of each character and it should work in turbo c Persistent 3
write a program to delete an item from a particular location of an linear array?   1
Why data types in all programming languages have some range? Why ritche have disigned first time likethat?Why not a single data type can support all other types? Excel 2
code snippet for creating a pyramids triangle ex 1 2 2 3 3 3   4
write a program to fined second smallest and largest element in a given series of elements (without sorting) Yahoo 9
2.Given the short c program that follows a. make a list of the memory variables in this program b.which lines of code contain operations that change the contents of memory? what are those operations? Void main( void) { Double base; Double height; Double area; Printf(“enter base and height of triangle :”); Scanf(“%lg”, &base); Scanf(“%lg”, &height); Area=base*height/2.0; Printf(“the area of the triangle is %g \n”,area); } Wipro 1
why we are using semicolon at the end of printh statment HCL 2
what is mallloc()?how it works? Excel 4
Describe for loop and write a c program to sum the series X + x2/2! + x3 /3! + …….. up to fifteen terms.   2
enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); } ME 4
I use turbo C which allocates 2 bytes for integers and 4 bytes for long. I tried to declare array of size 500000 of long type using the following code... long *arr; arr=(long *)(malloc)(500000 * sizeof(long)); It gives a warning that "Conversion may lose significant digits in function main"... And the resulting array size was very less around 8400 as compared to 500000. Any suggestions will be welcomed....   2
extern static int i func() { i =10; i++; printf("%d \n",i); } main() { i =20; printf("%d \n",i); func(); printf("%d \n",i); }   2
 
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