answersLogoWhite

0


Best Answer

#include<iostream>

class expand

{

public:

expand(unsigned long long num):value(num){}

std::ostream& operator()(std::ostream& out)const;

private:

unsigned long long value;

static const char * const units[20];

static const char * const tens[10];

};

const char * const expand::units[20] = {"zero", "one", "two", "three","four","five","six","seven",

"eight","nine", "ten", "eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen",

"eighteen","nineteen"};

const char * const expand::tens[10] = {"", "ten", "twenty", "thirty","forty","fifty","sixty","seventy",

"eighty","ninety"};

std::ostream &operator<< (std::ostream &out, expand number)

{

return(number(out));

}

std::ostream &expand::operator()(std::ostream &out) const

{

const unsigned long long quintillion=1000000000000000000;

const unsigned long long quadrillion=1000000000000000;

const unsigned long long trillion=1000000000000;

const unsigned long long billion=1000000000;

const unsigned long long million=1000000;

const unsigned long long thousand=1000;

const unsigned long long hundred=100;

const unsigned long long twenty=20;

const unsigned long long ten=10;

unsigned long long multiple=quintillion;

unsigned long long remain;

if(value>=thousand)

{

while(multiple>value&&(multiple!=quintillionmultiple!=quadrillion

multiple!=trillionmultiple!=billionmultiple!=millionmultiple!=thousand))

multiple/=1000;

out<<expand(value/multiple);

switch(multiple)

{

case(quintillion):out<<"-quintillion"; break;

case(quadrillion):out<<"-quadrillion"; break;

case(trillion):out<<"-trillion"; break;

case(billion):out<<"-billion"; break;

case(million):out<<"-million";break;

case(thousand):out<<"-thousand";break;

}

if(remain=value%multiple)

{

if(remain<hundred)

out<<"-and";

out<<"-"<<expand(remain);

}

}

else if(value>=hundred)

{

out<<expand(value/hundred)<<"-hundred";

if(remain=value%hundred)

out<<"-and-"<<expand(remain);

}

else if(value>=twenty)

{

out<<tens[value/ten];

if(remain=value%ten)

out<<"-"<<expand(remain);

}

else

out<<units[value];

return(out);

}

int main()

{

for(unsigned long long ull=10000000; ull<100000000; ++ull)

std::cout<<expand(ull)<<std::endl;

return(0);

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

const char* DigitToWord (int digit) {

switch (digit) {

case 0: return "zero";

case 1: return "one";

case 2: return "two";

case 3: return "three";

case 4: return "four";

case 5: return "five";

case 6: return "six";

case 7: return "seven";

case 8: return "eight";

case 9: return "nine";

default: return "error";

}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you convert digit to word in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you check whether a character is numeric in an alphanumeric field in C?

If the character's ASCII value is in the range of the digit characters, then it is a numeric. In ASCII, the range of digits is from '0' to '9' (48 to 57 decimal). Note that character constants such as '0' will implicitly convert to the constant integer 48 (the ASCII code for the character) so there is no need to remember the actual value; the compiler can determine this for us. The following function shows how one might test a character to see if it is a digit or not: bool is_digit (const char c) { return (c&gt;='0' &amp;&amp; c&lt;='9'); } The function will return true if the given character is a digit, otherwise it will return false.


A C variable cannot start with?

it should not start with _ or digit.


What to do to write a c program to input a number then a digit and findout the place value of that digit?

#include&lt;stdio.h&gt; int main() { int d,j=1,i,flag=0,count=0,k=0; int b[]; char a[],c; printf("enter the number="); scanf("%s",a); printf("enter the digit="); scanf("%c",&amp;c); printf("the place value of given digit is:"); for(i=0;a[i]!='\0';i++) { if(a[i]==c) { b[k]==a[i]-'0'; b[k]=b[k]=*j; flag=1; count++; k++; } j=j*10; } if(flag==1) { printf("the place value of given digit %c is:",c); for(i=0;i&lt;count;i++) printf("\n%d",b[i]); } else printf("your entered digit is not present in number"); return 0; }


How to design a DFA that accepts an identifier in c language?

letter -&gt; [a-zA-Z] digit -&gt; [0-9] identifier -&gt; letter|_(letter|digit|_)


To convert a hexadecimal number to tis binary equivalent in qbasic?

NOTE: The program below is written in the form of a straight forwards 'table/look up' chart. It will, quite simply, convert no more than 1 single hex digit character, at a time, into its binary number equivalent. If you wish to convert a whole entire string of hex digit characters together at once; then, I suggest you will need to 'modify' the program yourself by using, possibly, a 'FOR/NEXT loop' statement to extract out each separate hex character which needs to be converted from the users input/together with a function such as, 'MID$()'. ==== Here is a sample program RUN/Output... Please, enter your single character hex digit(0-9/A-F): ? C The binary equivalent of the above hex digit is: 1100

Related questions

Write the binary number in octane notation 10100100011?

The word is "octal", not octane. Take groups of three, from the right:10 100 100 011Now, convert each group to an octal digit (same as a decimal digit:2443The word is "octal", not octane. Take groups of three, from the right:10 100 100 011Now, convert each group to an octal digit (same as a decimal digit:2443The word is "octal", not octane. Take groups of three, from the right:10 100 100 011Now, convert each group to an octal digit (same as a decimal digit:2443The word is "octal", not octane. Take groups of three, from the right:10 100 100 011Now, convert each group to an octal digit (same as a decimal digit:2443


Write a program to convert a 2 digit BCD number into hexadecimal number?

Write a program to convert a 2-digit BCD number into hexadecimal


2 Write a program to convert a 2-digit BCD number into hexadecimal?

WRITE A PROGRAM TO CONVERT A 2-DIGIT bcd NUMBER INTO HEXADECIMAL


In a x c 128 a is a one-digit number and c is a two-digit number what numbers could a and c represent?

28X6


What is the root word for digit?

The root word for digital is digit.


How convert the binary number 110101001 to decimal then to octal?

You can use the Windows calculator to do the conversions. If you want to learn how to do it yourself:To convert binary to decimal, multiply the right-most digit with 1, the second digit (from the right) with 2, the third with 4, etc.To convert to octal, group the bits from the right to the left, in groups of 3. Convert each group to a decimal digit.


You are a three digit odd number your tens digit is one less than your hundredths digit but two more than your ones digit the sum of your digits is twenty who are you?

x = 100A + 10B + CA = B + 1B = C + 2&there4;A = C + 3A + B + C = 20&there4;(C + 3) + (C + 2) + C = 203C = 15C = 5&there4; B = 7&there4; A = 8The number is 875


How many 10 digit palindromic numbers are there?

well, i think if you use this you can find out. A = 1-9 ,B = 0-9 , C = 0-9 , D = 0-9 , E = 0-9 for 2digit numbers = A A for 3 digit numbers = A B A for 4 digit numbers = A B B A and so on till you get to for 8 digit numbers = A B C D D C B A for 9 digit numbers = A B C D E D C B A and last for 10 digit number = A B C D E E D C B A this should work...


How do you decrypt 3 digit numbers?

You can use C++ program to decrypt 3 digit number


What is a 5 digit word that means most important?

Not sure about a 5 digit word, but a 5 character word could be VITAL.


What does 19 F convert to in C?

-7.2 C


How do you convert the temperature 84.7 degree C to kelvin?

To convert deg C to Kelvin, simply add 273.15