C Program to Print Digit in Word
If a digit given then this C program prints or displays it in word. For example if a digit '4' is given this program prints in word 'four', if digit '5' is given it prints 'five' and so on for remaining digits.
C Program to Print Given Digit in Word
/* C Code to print digit in word */
#include<stdio.h>
int main()
{
int digit;
printf("\n \n Enter any digit in between 0-9: ");
scanf("%d",&digit);
switch(digit)
{
case 0:
printf("\n The number you entered is 'zero' \n \n");
break;
case 1:
printf("\n The number you entered 'one' \n \n");
break;
case 2:
printf("\n The number you entered 'two' \n \n");
break;
case 3:
printf("\n The number you entered 'three' \n \n");
break;
case 4:
printf("\n The number you entered 'four' \n \n");
break;
case 5:
printf("\n The number you entered 'five' \n \n");
break;
case 6:
printf("\n The number you entered 'six' \n \n");
break;
case 7:
printf("\n The number you entered 'seven' \n \n");
break;
case 8:
printf("\n The number you entered 'eight' \n \n");
break;
case 9:
printf("\n The number you entered 'nine' \n \n");
break;
default:
printf("\n You haven't enetered digit from 0-9 \n \n");
}
return 0;
}
Output:
Test Case 1: Enter any in between 0-9:0 The number you entered is 'zero' Test Case 2: Enter any in between 0-9:1 The number you entered 'one' Test Case 3: Enter any in between 0-9:2 The number you entered 'two' Test Case 4: Enter any in between 0-9:9 The number you entered 'nine'
Explanation:
Accept a digit from user to print it in word. We are storing the digit in variable nameddigit
. Then we are passing the value of digit
to switch case and depending on the value of digit
variable corresponding case gets executed and given digit is displayed in word.