luc077.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 08 Feb 2026
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
Write a program that receives an integer (less than or equal to nine digits in length) and prints out the number in words.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
void convert(long, char *);
char *one[] = {
"", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ",
"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ",
"Seventeen ", "Eighteen ", "Nineteen "
};
char *ten[] = {
"", "", "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "
};
int main()
{
long num;
printf("Enter a number (max 9 digits): ");
scanf("%ld", &num);
if (num <= 0)
{
printf("Zero\n");
}
else
{
printf("In words: ");
// Indian System: Crore, Lakh, Thousand, Hundred
convert((num / 10000000), "Crore ");
convert(((num / 100000) % 100), "Lakh ");
convert(((num / 1000) % 100), "Thousand ");
convert(((num / 100) % 10), "Hundred ");
convert((num % 100), "");
printf("\n");
}
return 0;
}
void convert(long n, char *suffix)
{
if (n > 19)
{
printf("%s%s", ten[n / 10], one[n % 10]);
}
else
{
printf("%s", one[n]);
}
if (n > 0)
{
printf("%s", suffix);
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59