Write a program using switch statement to print word equivalent of a number from 0 to 9, e.g. 3 should be displayed as "Three".
Answers
Program is given below.
EXPLANATION:
The switch case statement is used in a program when we have more than 1 options and each option would perform a different task. In the below program, each digit will print the number name of that digit. Like “Zero” for ‘0’, “One” for ‘1’ and so on.
#include <stdio.h>
void main()
{
int abc;
printf("Input Digit(0-9) : ");
scanf("%d",&abc);
switch(abc)
{
case 0:
printf("Zero\n");
break;
case 1:
printf("one\n");
break;
case 2:
printf("Two\n");
break;
case 3:
printf("Three\n");
break;
case 4:
printf("Four\n");
break;
case 5:
printf("Five\n");
break;
case 6:
printf("Six\n");
break;
case 7:
printf("Seven\n");
break;
case 8:
printf("Eight\n");
break;
case 9:
printf("Nine\n");
break;
default:
printf("Wrong input. \nPlease try again ....\n");
break;
}
}
Explanation: