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
write a program for area of circumference of shapes
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 ?
Write a program to model an exploding firecracker in the xy plane using a particle system
What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?
why nlogn is the lower limit of any sort algorithm?
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']
Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange
Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines
write a simple calculator c program to perform addition, subtraction, mul and div.
how to test pierrot divisor
Sir... please give some important coding questions asked by product companies..
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??
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.
Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?
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