Print single digit number in words - C Program

C program to read single digit number from user and print that number in words.

Solution:

In this program, read a single digit number from the user as an input. Check entered number using case statement whether it is single digit number and if it is not a single digit number then statement under default is executed. Here, break statement is used to control out of the program from switch statement.

If we do not used break statement then next cases are executed without checking for its value.

#include<stdio.h>
int main()
{
     int n;
     printf("Enter Single Digit Number : ");
     scanf("%d",&n);
     printf("-------------------------------");
     printf("\n\t");
     switch(n)
     {
          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("Not a Single Digit Number");
     }
     return 0;
}


Output:

digit number in words