answersLogoWhite

0

#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

12y ago

What else can I help you with?

Continue Learning about Engineering

A C variable cannot start with?

it should not start with _ or digit.


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.


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|_)


What is the meaning of n and 1 in C programming?

'n' can be an identifier, '1' is a digit

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


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.


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 many three digit numbers have the property that the middle digit is the arithmetic mean of the other two digits?

To find the three-digit numbers where the middle digit is the arithmetic mean of the other two digits, we denote a three-digit number as ( abc ), where ( a, b, c ) are its digits. The condition means ( b = \frac{a + c}{2} ), which implies ( a + c ) must be even. For ( a ) (1-9) and ( c ) (0-9), ( b ) must be an integer and a digit (0-9). The pairs ( (a, c) ) that yield valid integers for ( b ) can be counted, leading to 45 valid combinations for three-digit numbers. Thus, there are 45 such three-digit numbers where the middle digit is the arithmetic mean of the other two.


How do you decrypt 3 digit numbers?

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


Give you a 10 word sentence for the word digit?

In these cases the digit itself, or decimal multiples, seem to have been used.