luc077.c (1717B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 08 Feb 2026 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Write a program that receives an integer (less than or equal to nine digits in length) and prints out the number in words. 9 */ 10 11 /* Let Us C, Chap- 16 (Handling Multiple Strings), Qn No.: A(f) */ 12 13 /* This file is auto-generated by a bot. */ 14 /* This code is not compiled; it is for reference only. */ 15 16 17 #include <stdio.h> 18 #include <string.h> 19 #include <stdlib.h> 20 #include <ctype.h> 21 22 void convert(long, char *); 23 24 char *one[] = { 25 "", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", 26 "Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", 27 "Seventeen ", "Eighteen ", "Nineteen " 28 }; 29 30 char *ten[] = { 31 "", "", "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety " 32 }; 33 34 int main() 35 { 36 long num; 37 38 printf("Enter a number (max 9 digits): "); 39 scanf("%ld", &num); 40 41 if (num <= 0) 42 { 43 printf("Zero\n"); 44 } 45 else 46 { 47 printf("In words: "); 48 // Indian System: Crore, Lakh, Thousand, Hundred 49 convert((num / 10000000), "Crore "); 50 convert(((num / 100000) % 100), "Lakh "); 51 convert(((num / 1000) % 100), "Thousand "); 52 convert(((num / 100) % 10), "Hundred "); 53 convert((num % 100), ""); 54 printf("\n"); 55 } 56 57 return 0; 58 } 59 60 void convert(long n, char *suffix) 61 { 62 if (n > 19) 63 { 64 printf("%s%s", ten[n / 10], one[n % 10]); 65 } 66 else 67 { 68 printf("%s", one[n]); 69 } 70 71 if (n > 0) 72 { 73 printf("%s", suffix); 74 } 75 }