Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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"

Answers were Sorted based on User's Feedback



pls anyone can help me to write a code to print the values in words for any value.Example:1034 to ..

Answer / 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

pls anyone can help me to write a code to print the values in words for any value.Example:1034 to ..

Answer / vin

not sure wether this is the best in performance.
need to use switch case.

string = "";
for lengh of the number
{
switch(char)
{
case 1:
string = string + one;
case 2:
string = string + two;
case 3:
string = string + three;
}

{

but that gives only letters into numbers.
for ex 1043 will be onezerothreefour

this does not end here, please modify or add.

as this has to be transformed into numebrsystem

Is This Answer Correct ?    0 Yes 6 No

Post New Answer

More C Code Interview Questions

How we will connect multiple client ? (without using fork,thread)

3 Answers   TelDNA,


How to count a sum, when the numbers are read from stdin and stored into a structure?

1 Answers  


main( ) { static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3,a+4}; int **ptr = p; ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *++ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); ++*ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); }

2 Answers   Persistent,


#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d",s->x); printf("%s",s->name); }

3 Answers   Hexaware,


write a program to Insert in a sorted list

4 Answers   Microsoft,


main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }

2 Answers  


Who could write how to find a prime number in dynamic array?

1 Answers  


Is it possible to type a name in command line without ant quotes?

1 Answers   Excel, Infosys,


How to return multiple values from a function?

7 Answers  


main() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {‘s’,’o’,’m’,’e’,’\0’}; while (strcmp(str1,str2)) printf(“Strings are not equal\n”); }

1 Answers  


main() { if ((1||0) && (0||1)) { printf("OK I am done."); } else { printf("OK I am gone."); } } a. OK I am done b. OK I am gone c. compile error d. none of the above

5 Answers   HCL,


#include<stdio.h> main() { FILE *ptr; char i; ptr=fopen("zzz.c","r"); while((i=fgetch(ptr))!=EOF) printf("%c",i); }

1 Answers  


Categories