Works only upto 3 digit number
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
#include < stdio.h > #include < conio.h > void third_word(int); void second_word(int); void second_one(int); void first_word(int); void main() { int number, first, second, third; clrscr(); printf("Enter the number "); scanf("%d", & number); // Enter the number first = number / 100; //got first number second = (number % 100) / 10; // got second number third = (number % 100) % 10; // got third number if (first == 0 && second == 0 && third == 0) printf("Zero"); else if (first == 0 && second == 0 && third != 0) { third_word(third); } else if (first == 0 && second > 1) { second_word(second); third_word(third); } else if (first == 0 && second == 1) { second_one(third); } else if (first != 0 && second == 0) { third_word(first); printf(" hundard"); third_word(third); } else if (first != 0 && second == 1) { third_word(first); printf(" hundard"); second_one(third); } else if (first != 0 && second > 1 && third == 0) { third_word(first); printf(" hundard"); second_word(second); } else if (first != 0 && second > 1) { third_word(first); printf(" hundard"); second_word(second); third_word(third); } getch(); } void third_word(int input) { switch (input) { case 0: printf(""); break; case 1: printf(" one"); break; case 2: printf(" two"); break; case 3: printf(" three"); break; case 4: printf(" four"); break; case 5: printf(" five"); break; case 6: printf(" six"); break; case 7: printf(" seven"); break; case 8: printf(" eight"); break; case 9: printf(" nine"); break; default: printf(" Error"); } } void second_word(int input) { switch (input) { case 0: printf(""); break; case 2: printf(" twenty"); break; case 3: printf(" thirty"); break; case 4: printf(" fourty"); break; case 5: printf(" fifty"); break; case 6: printf(" sixty"); break; case 7: printf(" seventy"); break; case 8: printf(" eighty"); break; case 9: printf(" ninty"); break; default: printf(" Error"); } } void second_one(int input) { switch (input) { case 0: printf(" ten"); break; case 1: printf(" eleven"); break; case 2: printf(" twelve"); break; case 3: printf(" thirteen"); break; case 4: printf(" fourteen"); break; case 5: printf(" fifteen"); break; case 6: printf(" sixteen"); break; case 7: printf(" seventeen"); break; case 8: printf(" eighteen"); break; case 9: printf(" ninteen"); default: printf("Error"); } } |