Skip to content
UniCircle
MediumCodingString building and number logic

Write a number in words using lakh and crore

Question PROG-STR-103

Cheques and fee receipts in India write amounts in words using the Indian system: thousand, lakh (1,00,000) and crore (1,00,00,000). Convert each number to words.

Format rules:

  • Use lowercase words separated by single spaces. Do not write "and", hyphens or commas.
  • Leave out groups that are zero: 1,00,005 is one lakh five.
  • 0 is zero.

Example: 12,34,56,789 → twelve crore thirty four lakh fifty six thousand seven hundred eighty nine.

Constraints

  • 1 ≤ T ≤ 1000
  • 0 ≤ each number ≤ 999999999

Input and output

Input
First line: T. Then T integers, one per line.
Output
T lines, each the number in words.

Examples

Input 1

4
123456789
100005
0
1010

Output

twelve crore thirty four lakh fifty six thousand seven hundred eighty nine
one lakh five
zero
one thousand ten

1,00,005 skips the empty thousand and hundred groups. 1,010 is "one thousand ten".

Input 2

3
19
40
99999

Output

nineteen
forty
ninety nine thousand nine hundred ninety nine

The teens are irregular, and 40 is spelled "forty".

Show hints
  • Split the number into groups: crore = n / 10^7, lakh = (n / 10^5) % 100, thousand = (n / 1000) % 100, hundred = (n / 100) % 10, and the last two digits.
  • One helper that spells 0–99 covers every group except hundreds.
Show the explanation

Split by Indian place values, then spell each group with one helper for numbers below 100:

text
crore    = n / 10_000_000          (0–99 here)
lakh     = (n / 100_000) % 100
thousand = (n / 1_000) % 100
hundred  = (n / 100) % 10
rest     = n % 100

two(x): if x < 20, look the word up in a table (one … nineteen). Otherwise use tens[x / 10], plus ones[x % 10] if that digit is non-zero.

Build a list of parts, adding a part only when its group is non-zero (two(crore) + " crore", and so on), then join them with spaces. Handle n == 0 separately.

Testing advice: the bugs are almost always at the boundaries. Check 0, 10–19 (the "teens" are irregular), 20, 100, 101, 1000, 1,00,000, 1,00,00,000, numbers with zeros in the middle such as 10,00,001, and the maximum, 99,99,99,999. Writing these cases before coding is what interviewers want to see.

Variants: the international system groups by thousands (thousand, million, billion) using n / 1000^k. Real cheques write "Rupees … only". That is a formatting layer on top of this function.

Original UniCircle question. Last reviewed 22 Oct 2026.