C++ Program to Convert Number in Characters
In C++ language, we can easily convert number in characters by the help of loop and switch case. In this program, we are taking input from the user and iterating this number until it is 0. While iteration, we are dividing it by 10 and the remainder is passed in switch case to get the word for the number.
Let's see the C++ program to convert number in characters.
- #include <iostream.h>
- #include <conio.h>
- void main()
- {
- long int n,sum=0,r;
- cout<<"Enter the Number= ";
- cin>>n;
- while(n>0)
- {
- r=n%10;
- sum=sum*10+r;
- n=n/10;
- }
- n=sum;
- while(n>0)
- {
- r=n%10;
- switch(r)
- {
- case 1:
- cout<<"one ";
- break;
- case 2:
- cout<<"two ";
- break;
- case 3:
- cout<<"three ";
- break;
- case 4:
- cout<<"four ";
- break;
- case 5:
- cout<<"five ";
- break;
- case 6:
- cout<<"six ";
- break;
- case 7:
- cout<<"seven ";
- break;
- case 8:
- cout<<"eight ";
- break;
- case 9:
- cout<<"nine ";
- break;
- case 0:
- cout<<"zero ";
- break;
- default:
- cout<<"tttt ";
- break;
- }
- n=n/10;
- }
- getch();
- }
Output:
Enter the Number= 74254 seven four two five four
0 Comments