Program to read a number and print it out digit by digit as a series of words

#include <stdio.h>
#include <string.h>
main()
{
 /*Program to read a number and print it out digit by digit as a series of words*/
 char inputNumber[100];
 int numLen, i=0;
 printf("\nEnter a number: ");
 scanf("%s", inputNumber);
 printf("\n%s in words: ", inputNumber);
 numLen = strlen(inputNumber);
 for(i=0; i<numLen; i++)
 {
  switch(inputNumber[i])
  {
   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:
    break;
  }
 }
}
Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s