Program to convert Number in characters | C ++ program to convert number in characters ; To calculate the reverse of the number ; The remainder will give the last digit of the number ; Extract the first digit of the reversed number ; Match it with switch case ; Divide the number by 10 to get the next number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void NumbertoCharacter ( int n ) { int rev = 0 , r = 0 ; while ( n > 0 ) { r = n % 10 ; rev = rev * 10 + r ; n = n / 10 ; } while ( rev > 0 ) { r = rev % 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 << " UnValid ▁ " ; break ; } rev = rev / 10 ; } } #include <iostream> NEW_LINE int main ( ) { int n = 12345 ; NumbertoCharacter ( n ) ; return 0 ; }