Display numbers as English word in C Language
Write a Display numbers as English word program in C to read an integer and display each of the digit of the integer in English.User has to provide a number which will be printed as English word on the screen.
You can take an example of 2345 will be printed as two three four five.
Display numbers as English word in C Code
#include <stdio.h> void main () { int number, digit1, digit2, digit3, digit4, digit5; clrscr(); printf(“Enter a number (max 5 digits): “); scanf(“%i”, &number); if (number < 100000) { digit1 = number % 100000 / 10000; switch (digit1) { case 0 : printf(“Zero “); 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(“Unknown Interger “); break; } digit2 = number % 10000 / 1000; switch (digit2) { case 0 : printf(“Zero “); 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(“Unknown Interger “); break; } digit3 = number % 1000 / 100; switch (digit3) { case 0 : printf(“Zero “); 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(“Unknown Interger “); break; } digit4 = number % 100 / 10; switch (digit4) { case 0 : printf(“Zero “); 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(“Unknown Interger “); break; } digit5 = number % 10; switch (digit5) { case 0 : printf(“Zero “); 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(“Unknown Interger “); break; } } else { printf(“Entered Number is too long.”); } getch(); }
Leave a Reply