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) |
| Difficulty | Beginner (index: 2 / 10) |
Concepts¶
Beta Feature
This concept detection system is still in beta and may occasionally show incorrect or incomplete results.
- Pointers
- Recursion
- Array
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);
}
}
Explanation¶
Explain with AI
Copy the prompt below and paste it into any AI assistant.
You are explaining a C programming code to a beginner.
STRICT RULES:
- Only use the given code. Do NOT assume anything not present.
- Do NOT add extra examples.
- Keep explanation clear and short.
- If something is unclear, say "Not clear from code".
- Follow the exact format below. Do NOT change headings.
FORMAT:
[START]
## What it does
(Explain the overall purpose in 1-2 sentences)
## Step-by-step
(Explain how the code works in steps, simple language)
## Key Concepts
(List concepts like loop, condition, function, etc.)
## Notes
(Mention any limitations, errors, or assumptions)
[END]
CODE (luc077.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);
}
}