/* * Copyright (C) Linux-Manipur 2005-2008 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation. * * The program prints a given number in figure into words. The program will work * for numbers upto 9 digits. */ #include int print_words(int Value); int main() { unsigned long num ; unsigned long tens[8]={1, 100, 1000, 100000, 10000000, 100000000}; char tens_words[8][10]={"", "Hundred", "Thousand", "Lakh", "Core", ""}; int i; scanf ("%ld", &num); printf ("%ld = ", num); for (i = 4; i >= 0; i-- ) { if (print_words(num/tens[i])) printf ("%s ", tens_words[i]); num = num % tens[i]; } printf("\n\n"); return 0; } /* * This function prints a 2 digit number into words * The parameter Value is expected to be only 2 digit. */ int print_words(int Value) { char Ones[10][10] = {"", "One", "Two","Three","Four","Five","Six","Seven","Eight","Nine"}; char Teens[15][15] = {"Ten","Eleven","Tweleve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"}; char Tens[15][15] = {"", "", "Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"}; int digit1, digit2 ; if (Value == 0) return 0; digit1 = Value/10; digit2 = Value%10; if (digit1 > 9) { printf ("\nError:\n"); return 0; } //From 10 to 19 if (digit1 == 1 ) { printf ("%s ",Teens[digit2]); return 1; } //From 20 to 99 printf ("%s %s ", Tens[digit1], Ones[digit2]); return 1; }