luc077.c¶
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.
Metadata¶
| Property | Detail |
|---|---|
| Author | Amit Dutta amitdutta4255@gmail.com |
| Date | 08 Feb 2026 |
| License | MIT License (See the LICENSE file for details) |
Actions¶
💡 You can print or save this file by opening Raw and using your browser.
Source Code¶
#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);
}
}