write a c program to print the values in words
eg:- 143 written it has (one hundred and forty three)&
104, 114 are also written words

Answer Posted / vadivel t

Hi,

I have written code for only 3 digit numbers(u may not get
exact result for 100, 200, 113 etc ). This is just for an
idea from which u can build ur logic.
I accept... This code can be optimised.

Dont think that code is too lengthy... cos we hav to hav
limited if, else if or switch for this requirement.

Apply ur logic for 123455677 kind of nos.

#include <stdio.h>
/*Convert no to word... only for 3 digit nos*/
void ConvertToWord(int length);
char* Tens(int *a);
int Temp[10], Length = 0;

int main()
{
int No = 999, DupNo, i, j;
printf("ENTER THE THREE DIGIT NO: ");
scanf("%d", &No);
DupNo = No;
while(DupNo != 0)
{
Temp[Length] = DupNo % 10;
DupNo = DupNo / 10;
Length++;
}
printf("%d - ", No);
ConvertToWord(Length);
_getch();
}


void ConvertToWord(int Length)
{
while(Length != 0)
{
switch(Length)
{
case 0:
break;
case 1:
switch(Temp[Length - 1])
{
case 0:
break;
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;
}
Length--;
break;

case 2:
switch(Temp[Length -1])
{
case 0:
break;
case 1:
break;
case 2:
printf("TWENTY ");
break;
case 3:
printf("THIRTY ");
break;
case 4:
printf("FORTY ");
break;
case 5:
printf("FIFTY ");
break;
case 6:
printf("SIXTY ");
break;
case 7:
printf("SEVENTY ");
break;
case 8:
printf("EIGHTY ");
break;
case 9:
printf("NINETY ");
break;
}
Length--;
break;

case 3:
printf("%s HUNDRED AND ", Tens(&Temp[--
Length]));
break;
}
}

}

char* Tens(int *a)
{
char *ch;
switch(*a)
{
case 0:
ch = "ZERO";
break;
case 1:
ch = "ONE";
break;
case 2:
ch = "TWO";
break;
case 3:
ch = "THREE";
break;
case 4:
ch = "FOUR";
break;
case 5:
ch = "FIVE";
break;
case 6:
ch = "SIX";
break;
case 7:
ch = "SEVEN";
break;
case 8:
ch = "EIGHT";
break;
case 9:
ch = "NINE";
break;
}
return ch;
}

Is This Answer Correct ?    3 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How will you divide two numbers in a MACRO?

702


How can you pass an array to a function by value?

597


Write a program of advanced Fibonacci series.

702


Can a pointer point to null?

582


What is #include stdlib h?

608






main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }

910


What is the use of function in c?

702


What is the data segment that is followed by c?

600


What is the difference between exit() and _exit() function in c?

576


Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.

3685


can we have joblib in a proc ?

1650


What is property type c?

599


What is ambagious result in C? explain with an example.

2049


List some of the static data structures in C?

757


Explain how do you determine a file’s attributes?

588