pls anyone can help me to write a code to print the values
in words for any value.Example:1034 to print as "one
thousand and thirty four only"

Answer Posted / pavan_mustyala

Hi, This code works for 4 digit numbers(may be with some
minor exceptions). But i am trying a generic approach and
shall update very soon with more nicer solution.
/*************/
#include
char *arr1[10] =
{"One","Two","Three","Four","Five","Six","Seven","Eight","Ni
ne", "Ten"};
char *arr2[10] =
{"Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen"
,"Seventeen","Eighteen","Nineteen"};
char *arr3[10] =
{"Ten","Twenty","Thirty","Fourty","Fifty","sixty","Seventy",
"Eighty","Ninety","Hundred"};
char *arr4[10] = {"Hundred","Thousand"};

int CountGlobal;

int func(int);
void printWord(int, int);

int main(int argc, char* argv[])
{
int num = 2022;
int temp = num;
int count = 0;

// First count the number of digits in the given
number
while(temp)
{
temp /= 10;
count++;
}

CountGlobal = count;

while(count && num)
{
num = func(num);
count--;
}

return 0;
}

// Functions to print digits in words
int func(int num)
{
int temp = num;
int count = 0;


while(temp > 9)
{
temp /= 10;
count++;
}

printWord(temp,count+1);

while(count)
{
temp *= 10;
count--;
}

return(num - temp);
}

void printWord(int num, int count)
{

switch(count)
{
case 0:
//printf("%s", arr[num-1]);
break;
case 1:
printf("%s", arr1[num-1]);
break;
case 2:
printf("%s ", arr3[num-1]);
//printf("%s ", arr3[1]);
break;
case 3:
printf("%s ", arr1[num-1]);
printf("%s ", arr4[0]);
break;
case 4:
printf("%s ", arr1[num-1]);
printf("%s ", arr4[1]);
break;
case 5:
//printf("%s", arr[num-1]);
break;
default:
break;
}
}
/**********/

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

write a program for area of circumference of shapes

2029


why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

2261


Write a program to model an exploding firecracker in the xy plane using a particle system

3687


What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

3711


why nlogn is the lower limit of any sort algorithm?

2374






To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']

496


Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange

2860


Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines

3028


write a simple calculator c program to perform addition, subtraction, mul and div.

3144


how to test pierrot divisor

2259


Sir... please give some important coding questions asked by product companies..

1797


write a function to give demostrate the functionality of 3d in 1d. function prototye: change(int value,int indexX,int indexY,int indexZ, int [] 1dArray); value=what is the date; indexX=x-asix indexY=y-axis indexZ=z-axis and 1dArray=in which and where the value is stored??

4142


how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.

2138


Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?

3846


create a C-code that will display the total fare of a passenger of a taxi if the driver press enter,the timer will stop. Every 10 counts is 2 pesos. Initial value is 25.00

6309