write a short program to input a digit and print it in words
Answers
Answer:
int main()
{
int x;
cin >> x;
switch(x)
{
case 0:
cout << "Zero" <<endl;
break;
case 1:
cout << "One" <<endl;
break;
case 2:
cout << "Two" <<endl;
break;
case 3:
cout << "Three" <<endl;
break;
case 4:
cout << "Four" <<endl;
break;
case 5:
cout <<"Five" <<endl;
break;
case 6:
cout << "Six" <<endl;
break;
case 7:
cout << "Seven" <<endl;
break;
case 8:
cout << "Eight" <<endl;
break;
case 9:
cout << "Nine" <<endl;
break;
default:
cout << "Wrong Input" <<endl;
break;
}
return 0;
}
Explanation:
Program in java:
import java.util.*;
public class Digit{
public static void main(String args[]){
System.out.println("Enter a digit");
Scanner sc = new Scanner(System.in);
int number = sc.nextInt();
switch(number){
case 0: System.out.println("Zero.");
break;
case 1: System.out.println("One.");
break;
case 2: System.out.println("Two.");
break;
case 3: System.out.println("Three.");
break;
case 4: System.out.println("Four.");
break;
case 5: System.out.println("Five.");
break;
case 6: System.out.println("Six.");
break;
case 7: System.out.println("Seven.");
break;
case 8: System.out.println("Eight.");
break;
case 9: System.out.println("Nine.");
break;
default: System.out.println("None.");
}
}
}
Output:
Enter a digit : 5
Five.
Explanation:
- first i took number and stored it in number variable of int type
- then using switch case i checked the number and according to it i wrote the print statements so that if the number is 7 it goes to the case 7 and prints 'Seven" as output
---Hope you liked my answer and it is short when compared to other answer,mark brainliest if you liked my answer. :)