luc077.c
Problem Statement
luc077.c
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
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
● Author - Amit Dutta · Updated - 08 Feb 2026