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 (2248)
 C++ interview questions  C++ Interview Questions (1106)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (644)
Question
Write a program in c to input a 5 digit number and print it
in words.
 Question Submitted By :: Niharika_dash
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Write a program in c to input a 5 digit number and print it in words.
Answer
# 1
#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;
like this print upto case 0 , (ie) after case 9 ... put
case 0.... and finish the switch and close the loop.......
 
Is This Answer Correct ?    116 Yes 182 No
Vignesh1988i
[Nil]
 
  Re: Write a program in c to input a 5 digit number and print it in words.
Answer
# 2
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 76 No
Prawin62
 
 
 
  Re: Write a program in c to input a 5 digit number and print it in words.
Answer
# 3
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 ?    22 Yes 34 No
Vignesh1988i
 
  Re: Write a program in c to input a 5 digit number and print it in words.
Answer
# 4
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 27 No
Manoj Kumar
 
  Re: Write a program in c to input a 5 digit number and print it in words.
Answer
# 5
#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 20 No
Sunil
 
  Re: Write a program in c to input a 5 digit number and print it in words.
Answer
# 6
# 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 ?    21 Yes 34 No
Swathi
 
  Re: Write a program in c to input a 5 digit number and print it in words.
Answer
# 7
# 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 ?    14 Yes 14 No
Rakesh.bit
 
  Re: Write a program in c to input a 5 digit number and print it in words.
Answer
# 8
/*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 ?    14 Yes 8 No
Mayank
 
  Re: Write a program in c to input a 5 digit number and print it in words.
Answer
# 9
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
 
  Re: Write a program in c to input a 5 digit number and print it in words.
Answer
# 10
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
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
Can we include one C program into another C program if yes how? Infosys 7
Why does not use getgh(); and <conio.h> in c language. Elofic 2
What is Full Form of C and Why We use C   16
What is diffrance between declaration and defination of a variable or function   4
how to get the starting address of file stored in harddisk through 'C'program. Siemens 2
What is the relation between # and include<stdio.h> HCL 5
write the output of following code .. main() { static int a[]={10,20,30,40,50}; int *ptr=a; static int arr[2][2]={1,2,3,4}; char str[]="ABCD * 4#"; char *s=str+2; int i,j; for(i=0;i<5,i++) printf("%d",*ptr++); for(i=0;i<2;i++) for(j=0;j<2;j++) printf("%d\n",*(*(n+i)+j)); printf("%c\n%c\n%c\n",*(str+2),*s++,*--s); }   1
how write a addtion of two single dimensional array using of pointer in c language? DRDO 3
what is the need for main function in c?   5
how i m write c program 1.check prime number 2.prime number series   1
please give code for this 1 2 4 7 11 16 Wipro 7
Write a program for print infinite numbers Wipro 3
 
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